route model binding
implicit and explicit binding
public function (request $requst, $id)
{
}
web.php
users/1
route::get('users/{users}' function (\app\models\user $users)
{
echo "<pre>";
print_r($users);
exit:
})
users/trev
'users/{users:first_name}'
or controler
getUsers(request $request, user $users)
{
}
users/1/brand/{brand}
route::get('users/{users}/brand/{brand}' function (\app\models\user $users,(\app\models\brand $brand)
{
echo "<pre>";
print_r([$users,$brand]);
exit:
})
controller
getUsers(request $request, user $users, Brand $brand)
{
}
route service provide boot
explicit binding
route service provider
function boot
route::model('users',User::class);
route::get('users/{users}' function ( $users)
{
echo "<pre>";
print_r([$users,]);
exit:
})
controller
getUsers(request $request, $users)
{
}
in boot of routesrevice provider
route::bind('usrs',function ($value){
return user::where('first_name',$value)->first() ?? abort();
});
url/users/bird
user app/models/user
No comments:
Post a Comment