mercredi 10 juin 2020

Cannot get $user from route in controller method with Laravel

For which possible reason dd(User::find(123)->id) returns the expected user id while dd($user->id) returns null when opening http://backend.test/my-route/123 ?

routes/api.php:

Route::get('my-route/{user}', 'My\Path\To\Controllers\MyController@myMethod');

My/Path/To/Controllers/MyController.php:

    public function myMethod(User $user)
    {
        dd(User::find(123)->id);
        dd($user->id);
    }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/30vtdtI
via IFTTT

Aucun commentaire:

Enregistrer un commentaire