Posted in Laravel, PHP

Route Model Binding : Multiple Route Key

When using Implicit Model Binding, you can use getRouteKeyName  to use alternative column such as slug instead of id to inject a model instance directly inside routes. Now, model can be bound only with slug column. When you think to use id, the binding fails.  Continue reading “Route Model Binding : Multiple Route Key”

Posted in Laravel, PHP

Implicit Model Binding : Changing Model’s Route Key

When using Implicit Model Binding, the model can be fetched using the id parameter by default. Consider when you need to list product details for an id, you use:

Route::get('product/{id}', 'ContactsController@index');

Continue reading “Implicit Model Binding : Changing Model’s Route Key”