I found a different error. I tried to delete book by id. i have data for example
--------------
| id | name |
--------------
| 1 | book1 |
| 2 | book2 |
| 3 | book3 |
so, when I will delete books with id 2, then the controller always receives id 3. and when i tries to delete id 1, that remains the case, the controller gain id 3 (always the last record)
this view blade
@foreach($datas as $data)
<a href="# {{ $data->id }}"
onclick="event.preventDefault();
document.getElementById('remove-form').submit();"
rel="tooltip" title="Hapus" class="btn btn-danger">
</a>
<form id="remove-form" action="{{ url('/dashboard/book/delete/'. $data->id) }}" method="post">
{{ csrf_field() }}
{{ method_field('DELETE') }}
</form>
@endforeach
this route
Route::group(['namespace' => 'Backend'], function ()
{
Route::resource('/dashboard/book', 'BookController'); //
Route::delete('/dashboard/book/delete/{id}', 'BookController@destroy');
}
this controller
public function index()
{
$datas = Book::all();
return view('backend.bookview', compact('datas'));
}
public function destroy($id)
{
Book::where('id', $id)->delete();
return redirect('/dashboard/book')->with('ok', translate('back/book.destroyed'));
}