Hello I'm still a beginner at laravel, I got a problem on the delete method.
this my controller
public function destroy($id)
{
$home = Home::find($id);
$home -> delete();
return back();
}
this my balde
<div class="col-6 sampah">
<form action="{{ route('home.destroy', $home->id) }}" method="POST">
@csrf
@method('DELETE')
<a href="">
<i class="bi bi-trash3-fill" style="width: 10px; height:10px;"></i>
</a>
</form>
</div>
this my route
Route::resource('home', 'App\Http\Controllers\TodosController')->middleware('auth');
When I press the delete button, why doesn't it work? Where is the problem? pls, help.
At the first you need to get what you want to delete this is an example for you it would be your controller:
///REPLACE Crud with your MODEL////
public function destroy(Request $request,$id){
$data = Crud::findOrFail($id);
$data->delete();
return redirect('YOUR_HOME_PAGE')->with('success', 'User is successfully deleted');
}
this is your blade:
<td>
<form action="{{ route('home.destroy', $row->id) }}" method="post">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-xs btn-danger btn-flat show_confirm" data-toggle="tooltip" title='Delete'>Delete</button>
</form>
</td>
</tr>