I'm creating the delete functionality for a "speaker" in my system. I keep getting the below error:
MethodNotAllowedHttpException in RouteCollection.php line 233:
in RouteCollection.php line 233
at RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'PUT', 'PATCH', 'DELETE')) in RouteCollection.php line 220
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD', 'PUT', 'PATCH', 'DELETE')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 533
My routes (shown below) indicate that I can delete a speaker, so I'm setting up my form HTML like:
@foreach($speakers as $speaker)
<form action="/admin/speakers/" method='POST' id="delete-speaker-">
<tr>
<td> </td>
<td class="text-center">
<a onclick="event.preventDefault();console.log('here');document.getElementById('delete-speaker-').submit();"
id='delete-' class="btn btn-danger btn-sm">
Delete
</a>
</td>
</tr>
</form>
@endforeach
Based on what I've seen on various forum posts this should work. I'm baffled because I must not be seeing some small detail that I've messed up. It looks like everything is correct. When I see the MethodNotAllowed I can refresh the page without the typical "Are you sure you want to re-submit this form" which I find odd. That's probably a hint at the problem but I'm not sure what next step I should take to try to resolve this.
Here's my route list:
+--------+-----------+-------------------------------+------------------+------------------------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+-------------------------------+------------------+------------------------------------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | admin/dashboard | | App\Http\Controllers\Admin\DashboardController@index | web,auth |
| | GET|HEAD | admin/speakers | speakers.index | App\Http\Controllers\Admin\SpeakersController@index | web,auth |
| | POST | admin/speakers | speakers.store | App\Http\Controllers\Admin\SpeakersController@store | web,auth |
| | GET|HEAD | admin/speakers/create | speakers.create | App\Http\Controllers\Admin\SpeakersController@create | web,auth |
| | DELETE | admin/speakers/{speaker} | speakers.destroy | App\Http\Controllers\Admin\SpeakersController@destroy | web,auth |
| | PUT|PATCH | admin/speakers/{speaker} | speakers.update | App\Http\Controllers\Admin\SpeakersController@update | web,auth |
| | GET|HEAD | admin/speakers/{speaker} | speakers.show | App\Http\Controllers\Admin\SpeakersController@show | web,auth |
| | GET|HEAD | admin/speakers/{speaker}/edit | speakers.edit | App\Http\Controllers\Admin\SpeakersController@edit | web,auth |
via Webnet