lundi 21 février 2022

Laravel: how model gets injected from route parameter

I've seen the following route:

Route::prefix('/users/{user}')->group(function () {
   Route::get('groups/{group}', 'UserGroupController@show');
}

And in UserGroupController:

use App\Group;

    public function show(Request $request, User $user, Group $group)
    {
        dd($group);
    }

My question is how does the $group model object gets constructed here from a raw route parameter string?

My guess is laravel's service container does the following magic (maybe sth like

  1. Injecting the Group model,
  2. then do sth like Group::where('id', $group)->first()

but unsure about this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire