'Laravel CRUD - Delete - Not route found
Error:
Route [events.destroy] not defined. (View: C:\xampp\htdocs\Event-Manager-Project\resources\views\events\admin.blade.php)
In my view, admin i have this about the delete:
<form action="{{ route('events.destroy', $event->id) }}" method="POST">
<a href="/admin/edit/{{$event->id}}" class="far fa-edit"></a>
@csrf
@method('DELETE')
<button type="submit" class="far fa-trash-alt" ></button>
</form>
In controller this:
public function destroy($id)
{
$event = Event::find($id);
$event->delete();
return redirect('/admin');
}
And using a route resource:
Route::resource('admin', 'App\Http\Controllers\EventController');
Solution 1:[1]
change the code to this
<form action="{{ route('events.destroy', $event->id) }}" method="post">
<input type="hidden" name="_method" value="DELETE" />
<input type="submit" value="Delete" name="Delete" id="btnExc" class="btn btn-sm btn-danger glyphicon glyphicon-trash" accesskey="x"/>
</form>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | brombeer |
