qqmydarling
qqmydarling

Reputation: 177

Laravel named route with {parametr}

Route::match(['patch','put'],'/edit/{id}', 'TestController@update')->name('update');

using route() helper in form action I expected to see

https://example.com/edit/1

And what I get using {{ route('update', $article->id) }} is https://example.com/edit?1

Any ideas how to resolve this?

Upvotes: 1

Views: 40

Answers (2)

Michio
Michio

Reputation: 297

I tried your example and it seems to work as expected. Going by the ? in the URL, my guess would be that it is a GET instead of POST in the form? Could you confirm that?

Upvotes: 0

Brian Lee
Brian Lee

Reputation: 18197

Try passing the id in as an array:

route('update', ['id' => $article->id])

and make sure the form's method attribute is post as well as setting the correct _method value within the form:

<form action="{{ route('upate', ['id' => $article->id]) }}" method="post">
    {{ method_field('patch') }}
</form>

Upvotes: 2

Related Questions