Laravel's implicit route model binding isn't working. It is not looking up the record indicated by the identifier. I'm getting a brand new model object.
Given this code:
Route::get('users/{user}', function (App\User $user, $id) {
$user2 = $user->find($id);
return [
[get_class($user), $user->exists, $user],
[get_class($user2), $user2->exists],
];
});
And this URL: /users/1
I get this output:
[["App\\User",false,[]],["App\\User",true]]
I'm on PHP 7.2 and Laravel 5.6.
Additional Information
I've successfully accomplished implicit route model binding in other Laravel projects. I'm working on an existing codebase. As far as I can tell, the feature hasn't been used previously.
The user record exists. It has not been soft deleted. The model does not use the SoftDeletes
trait.
I've tried this using various unique route names and other models.
I've checked the App\Http\Kernel
class for the usual culprits. $middlewareGroups
has \Illuminate\Routing\Middleware\SubstituteBindings::class,
in the web
section and $routeMiddleware
contains 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
.
SubstituteBindings
isn't running. – lagbox