I just upgraded my Laravel project from 5.2 to 5.3. And it seems that route model binding doesn't work correctly.
I use a sluggable package.
Route::get('team/{team}', function (App\Models\Team $team) {
dd($team);
});
But when I use (for example) the code above with a slug or an id, I just get a new model instance instead of the associated model. Even if I remove the sluggable trait from the model and use a id in the route instead. The 404 page doesn't display when I use an id which not exists.
I'm not sure if this is a bug in the package, in Laravel or that I'm just doing something wrong. Any ideas?
Looks like you forgot to add the new middleware as listed in the upgrading docs.
Worked like a charm. Cheers!
It would be very helpful if you could be more specific. You are talking about Binding Substitution Middleware section in the upgrading docs, right?
I get this issue too with the same package. I downloaded a fresh install of laravel 5.3, and imported my project inside, so, I don't think I could have forgotten a Middleware...
Don't really know where to look
It hasn't anything to do with the package. My problem was that I forgot to add the \Illuminate\Routing\Middleware\SubstituteBindings::class, to the web middlewareGroups and to the routeMiddleware. Which is described in the Upgrade Guide under Middlware.
Ok, in my case, I have the SubstituteBindings middleware added in both arrays, as I say, I'm importing my small project in a fresh copy of Laravel 5.3...
Same as @xoco70 . Some routes doesn't work.
However I have tried this thing:
Route::get('incidencia/{incidencia}', 'IncidenciesController@show');
Route::resource('incidencia', IncidenciesController::class);
The first line works! But the second one doesn't (after removing first one).
Hey there! I'm having something similar.
I've followed the upgrade guide and added the new Middleware. It works fine when the model exists, GET/{id} of an existing model retrieves the model. However, when the model doesn't exist in the database the API gives a 500 with the following error:
local.ERROR: exception 'Illuminate\Database\Eloquent\ModelNotFoundException' with message 'No query results for model [App\Models\User].' in /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Router.php:949
Shouldn't it just return 404?
Most helpful comment
Looks like you forgot to add the new middleware as listed in the upgrading docs.