I get a really weird error after I have updated to Laravel 6.4. Have I missed something?
Doesn't work
{{ action('Admin\OfferController@post', ['id'=>$offer->offer_id,'post'=>0]) }}
Works
{{ action('Admin\OfferController@post', [$offer->offer_id, 0]) }}
Error
Missing required parameters for [Route: offers.edit]
Laravel 6.3(ish, I think) made the action url generator a little more strict, if you're naming the param (i.e. 'id'=> 0
) then you have to make sure that name matches exactly the name of the param in the route definition.
You can find the name of the param required by using php artisan route:list
and looking for the route you're trying to post to. In this case I suspect it should be 'offer' => $offer->offer_id
instead of 'id' => $offer->offer_id
but that's only if you generated the route using the route::resource method.
For example. in an app I'm currently working on the I have the following
Route::resource('/articles', 'ArticlesController');
Which generates the following route for updating an article
PUT /articles/{article}
So to use the action URL generator I have to do the following
action('ArticlesController@update', ['article' => $article->id])
The reason your second example works is because, in the absence of you telling it what that first variable is called, the URL generator assumes that the first param satisfies the param needed to generate the route.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With