#5 Laravel 6 Basics | Routing (V) | Route Model Binding | Implicit/Explicit Binding

Published: 01 January 1970
on channel: Stack Developers
921
16

In Part-5 of Laravel 6 Basics, we will continue learn about Routing in detail.

We will keep experimenting with lot of route functionalities in new Laravel 6 website and in E-com series.

In this video, we will learn about Route Model Binding in which we can bind the model with route itself without even using the Controller. We can achieve this with Implicit Binding and Explicit Binding. Both bind the model with route to give the desired output and retrieve the model that corresponds to that ID. Just the way of doing is different but their purpose is same.

Implicit Binding

First create users table and add few records in it. Add User model that we will connect with Route to return the desired result.

We will create user blade file where we will send output.

Here we don't required any Controller and we can directly send data from model to blade file.

You need to pass User Id in Route URL to get the User details as by default it will pick from Id but we can change it.

Customizing The Key Name

If you would like model binding to use a database column other than id when retrieving a given model class, you may override the getRouteKeyName method on the Eloquent model.

Explicit Binding

To register an explicit binding, use the router's model method to specify the class for a given parameter. You should define your explicit model bindings in the boot method of the RouteServiceProvider class.


Watch video #5 Laravel 6 Basics | Routing (V) | Route Model Binding | Implicit/Explicit Binding online without registration, duration hours minute second in high quality. This video was added by user Stack Developers 01 January 1970, don't forget to share it with your friends and acquaintances, it has been viewed on our site 921 once and liked it 16 people.