Update -> Laravel

1.We will place a button in the list we want to update

View-{button}/backend

View-{button}/FrontEnd

  1. In web.php

    we'll take two routes one will be for getting all the stuff that has to be edited and the other will be put which will help in updating everything.

     Route::get('/pet/edit','Pet_Controller@edit');
     //pet_controller@edit is another way to access controller 
     Route::put('/pet/update/{id}',[Pet_Controller::class,'update']);
    
  2. Copy that previous form and name it edit.blade.php

    Few things that you have to add is

    • @method('Put')

    • action URL gets changed because it will be getting the id of your record.

    • $pet->PetName is an object calling the attribute of the database

  1. Controller work for updating and editing

    In function edit = we will find id and then compact it in $data then pass it to view edit.blade.php with all the data found with that $id

    Meanwhile, in the update, we'll be updating all the changes you have made in those input fields.

Now the update button is working.

Thanks.