Laravel Route Model Binding: Default, Custom and Laravel 7

preview_player
Показать описание
I explain how Route Model Binding works, how can we use it outside of Resource Controllers, how can we customize the Key for the binding, and also what's new in Laravel 7 about the binding.

Related links
- - - - - - - -

- - - - -

- - - - -

- - - - -
Рекомендации по теме
Комментарии
Автор

Great video, one thing which is great for troubleshooting issues, is to list your routes, as that will confirm what variable the route is expecting
in your controller so everything works correctly.

chqshaitan
Автор

hi povilas, If you use Gate, in your controller you can use constructor
{

$this->middleware('can:create-project', ['only' => ['create', 'store']]);
$this->middleware('can:edit-project', ['only' => ['edit', 'update']]);
$this->middleware('can:delete-project', ['only' => ['destroy']]);
}
see App/Http/kernel routeMiddleware : 'can'

DRY ;)

Abdel_monaam_
Автор

Thank you, your video helped me a lot

sergey_gabrielyan
Автор

Thanks for the hint.
Issue :- Model binding was not working...
Routes :-
Route::resources([
'cart' => 'CartitemController'
]);
Controller :-
public function update(Request $request, Cartitem $cartitem){}
In this condition model binding was not working.
So I rename the variable $cartitem to $cart same as my url name, and now it is working fine :)
public function update(Request $request, Cartitem $cart){}

SunilKumawatbfcj
Автор

Amazing tutorials, keep shooting! +1 subscriber :-)

extsania
Автор

Yeah it looks great, however how to use Route Model Binding if route is 'with_two_or_more_words' ?

gidaban
Автор

Howdy,
I tried what you explained on laravel 8 but unfortunately it doesn't work :(

fbymita
Автор

Ohk. Here comes my question i wanted to ask a long time ago. See at 4:10 when the name of parameter in route and the parameter in method differs, there you just die and dump using dd(); But if you continue your logic instead of dd or lets consider edit method, which gets param and passes to view. There you differenciate the spellings and see laravel goes in loading page again and again and browser goes mad. What can of behaviour is that ?? What are the scenes behined it. Somebody must agree with me if ever faced this problem. Respect from Pakistan

nabeelyousafpasha
Автор

how to use route model binding eg: column name is username and value is 'john doe'?

noelkalel