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

Publicado el: 01 enero 1970
en el canal de: 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.


En esta página del sitio puede ver el video en línea #5 Laravel 6 Basics | Routing (V) | Route Model Binding | Implicit/Explicit Binding de Duración hora minuto segunda en buena calidad , que subió el usuario Stack Developers 01 enero 1970, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 921 veces y le gustó 16 a los espectadores. Disfruta viendo!