laravel route model binding

 route model binding

implicit and explicit binding


implicit binding

mutatos/1

get('mutators/{id}',
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


route servidfe provicder


user app/models/user







No comments:

Post a Comment

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...