Home > Back-end >  edit and update not detected on laravel 8
edit and update not detected on laravel 8

Time:11-30

I want to edit and update data in my table record, when I click update on the data record, no previous data appears, please help

this my Route

Route::resource('/servicepending', ServicePendingController::class)->middleware('auth');

Route::resource('/servicepending', ServicePendingController::class)->except([
    'show', 'destroy', 'edit', 'update'
])->middleware('auth');

Route::get('/servicepending/{id}/edit', [ServicePendingController::class, 'edit'])->middleware('auth');
Route::put('/servicepending/{id}', [ServicePendingController::class, 'update'])->middleware('auth');

this my Controllers

    public function edit(Barangsp $barangsp)
    {   
        
        return view('servicepending.edit', [
            'barangsp' => $barangsp
        ]);
    }
    public function update(Request $request, Barangsp $barangsp)
    {
        $validatedData = $request->validate([
            'title' => 'required|max:255',
            'serialnumber' => 'required|max:255',
            'pelanggan' => 'required|max:255',
            'model' => 'required|max:255',
            'kerusakan' => 'required|max:255',
            'teknisi' => 'required|max:255',
            'perbaikan' => 'required|max:255',
            'snkanibal' => 'required|max:255',
            'nosparepart' => 'required|max:255',
        ]);

        Barangsp::where('id', $barangsp->id)
                  ->update($validatedData);
        
        return redirect('/servicepending')->with('success', 'Data has been update');
    }

And This my example View

<div >
        <form method="post" action="/servicepending/{{ $barangsp->id }} > 
        @method('put')
        @csrf 
        <div >
          <label for="title">Tanggal</label>
          <input type="text"  id="title" 
          name="title" placeholder="Masukan Tanggal" required autofocus value="{{ old('title', $barangsp->title) }}">
        </div>
        <button type="submit" >Ubah Data</button>
      </form>
    </div>

enter image description here enter image description here

I have tried several ways by changing the controller and route, because I think there is no problem with the view,

I hope, when you click edit, the previous record data will appear

CodePudding user response:

Kindly show your edit.blade.php and the controller loading the edit form page

CodePudding user response:

that code solve by my own, thanks for helping me answer and give solution

  • Related