'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
- Injecting the Group model,
- then do sth like
Group::where('id', $group)->first()
but unsure about this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
