Kuraist
Kuraist

Reputation: 3

Laravel 5. Dont work put and delete methods

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?

Upvotes: 0

Views: 502

Answers (2)

Clément Rigo
Clément Rigo

Reputation: 430

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

Upvotes: 0

Pawel Bieszczad
Pawel Bieszczad

Reputation: 13325

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.

Upvotes: 1

Related Questions