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>
The CIN
is the primary key
for example: BB1194