0

NOTE : I use the same delete/edit function for all the tables in my project.

function confirmDelete(link, id) {
    ...
    .then((willDelete) => {
    if (willDelete) {
      window.location.href = "/del-"+link+id;
      swal("Supprimé avec succès!", {
      icon: "success",
    });
    ...
  }

Delete function in PersonnelController :

public function destroy(Request $request, $cin)
{
    $personnel = Personnel::findOrFail($cin);
    $personnel -> delete();
    redirect('/personnel');
}

Route :

Route::get('/del-pers/{cin}', 'PersonnelController@destroy')->name('personnel.destroy');

the edit button shows me this error in edit page :

Property [cin] does not exist on this collection instance.

The Show button works properly and show me the record, but the delete button does'nt work :

<a class="btn btn-sm bu5" href="/detail-pers/{{ $pers->cin }}"><i class="fa fa-eye"></i></a>
<a class="btn btn-sm bu5" href="/edit-pers/{{ $pers->cin }}"><i class="fa fa-edit "></i></a>
<a class="btn btn-sm bu5" onclick="confirmDelete('pers/', {{$pers->cin}})"><i class="fa fa-trash-alt"></i></a>
      

Delete button problem with red vector

The CIN is the primary key

for example: BB1194

Aymane Lassfar
  • 133
  • 2
  • 11
  • https://stackoverflow.com/questions/41366092/property-title-does-not-exist-on-this-collection-instance the solution at this might work for. – Hirdesh Vishwdewa Aug 05 '20 at 11:29

1 Answers1

1

If you provide us with your routes, we can give you a better answer. Anyhow, if you define your delete rout like below

Route::get('del-pers/{id}' , ....)

It should work properly. Alternatively, you can send your request withquery parameters like 'del-pers?cid=55' and get it through

$request->cid 

inside your controller.

Ala Shariaty
  • 108
  • 9
  • Thank you for your answer, But I can't do that, because it will be a direct delete, and my function ask the user to confirm the delete operation, then he presses on OK button. I added the route in my question !! – Aymane Lassfar Aug 05 '20 at 12:09