0

Today stopped working DELETE and PUT methods with link_to_route

MethodNotAllowedHttpException in RouteCollection.php

Route:

Route::put('inits/{init_id}/publication', ['as' => 'init.publication', 'uses' =>'Inits\InitsController@putPublicationInit']);

Blade:

{!! link_to_route('init.publication',
        'Publication',
        $init->id,
        ['class' => 'btn btn-control gray-lighter',
        'data-method' => 'put',
        'data-token' => csrf_token()]
) !!}

DELETE methods leads to GET. What is the problem?

craig_h
  • 31,871
  • 6
  • 59
  • 68

2 Answers2

1

You cannot have a link that will make a POST request. All Links are GET requests. Use form or javascript to trigger a POST/DELETE/PUT request when the link is clicked.

Here's a question with an example of how to accomplish that.

Community
  • 1
  • 1
Pawel Bieszczad
  • 12,925
  • 3
  • 37
  • 40
  • You must have had the link in a form or some javascript that ran with it. `'data-method' => 'put', 'data-token' => csrf_token()` with this code I would assume you have some javascript that converts clicks to ajax requests. – Pawel Bieszczad Oct 27 '15 at 13:33
  • Thanks! Yea, I found it. laravel.js was included https://gist.github.com/JeffreyWay/5112282 – Rustem Mukhamadiev Oct 27 '15 at 14:17
0

For DELETE, POST and PUT requests, you need to use a form request.

You are generating a simple link, which will lead to a GET request on the page.

Have a look at the doc : http://laravel.com/docs/5.1/routing#form-method-spoofing

Hope it helps

Clément Rigo
  • 420
  • 1
  • 3
  • 10