I am trying to use Laravel's (5.3) destroy method to delete an object when I push a button, however I'm getting a MethodNotAllowedHttpException.
My route is
Route::delete('/admin/add/{id}', 'ItemController@destroy');
The destroy method is
public function destroy($id)
{
$items = Item::where('id', $id)->get();
foreach ($items as $item)
$item->delete();
return redirect('/admin/add');
}
My form is
<form action="" method="POST">
<div class="modal-footer no-border">
<button type="submit" class="btn btn-primary">Delete</button>
</div>
</form>
I checked the existing routes (php artisan route:list), and the delete one is showing:
DELETE | admin/add/{id} | | App\Http\Controllers\ItemController@destroy
The error that I am getting is
in RouteCollection.php line 218
at RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'POST')) in RouteCollection.php line 205
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD', 'POST')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 766
at Router->findRoute(object(Request)) in Router.php line 621
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 53
at require('/Users/username/Sites/blades/public/index.php') in server.php line 133
Per the Laravel routing instructions, I'm using a form and spoofing the DELETE action using a POST method, but I'm still getting an exception. Any help would be appreciated.
NOTE: I followed the full example at http://ift.tt/24a86XT, and it works perfectly fine there. My attempts at recreating this in a different project is what's causing the issue.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2v9Ii3Y
via IFTTT
Aucun commentaire:
Enregistrer un commentaire