2
votes

I am using a resource Laravel route defined by the following line in my routes.php :

Route::resource('test', 'App\Controllers\Teacher\TestController', ['only' => ['index', 'create', 'destroy']]);

The index method works fine. In the template of index I have created a form in order to remove an item of the list.

<form method="DELETE" action="{{ URL::action('App\Controllers\Teacher\TestController@destroy', $audit->id ) }}">
    <input type="submit" value="Remove" />
</form>

The URL is correctly generated by Laravel but when I post this form I get the following error :

exception 'Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException' in /var/www/project/bootstrap/compiled.php:5365

I have already try to change DELETE by POST in the method attribute of my form but it doesn't work.

I also read this post but it doesn't help me : MethodNotAllowedHttpException on resource defined method Laravel-4

2

2 Answers

6
votes

When you manually create your form you should use POST as method, and use _method input with delete value this way:

<form method="POST" action="{{ URL::action('App\Controllers\Teacher\TestController@destroy', $audit->id ) }}">
    <input type="hidden" name="_method" value="DELETE" />
    <input type="submit" value="Remove" />
</form>

Reference in Laravel documentation for form method spoofing

0
votes

Try this:

<form action="/test" ....>