Laravel: Difference between revisions
Jump to navigation
Jump to search
Adamcolton (talk | contribs) |
Adamcolton (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
== | == Implicit Route Binding == | ||
From [https://laracasts.com/series/whats-new-in-laravel-5-2/episodes/1 this] video | |||
Route::get('users/{user}', function(App\User $user){ | |||
return $user; | |||
}); | |||
If the arg name matches the token, it will magic that value into place. With the type hinting, it will find a user with the primary key given in the url. | |||
To add a | To use something other than the primary key, you have to add a route binding in RouteServiceProvider. | ||
Revision as of 21:52, 21 January 2016
Implicit Route Binding
From this video
Route::get('users/{user}', function(App\User $user){
return $user;
});
If the arg name matches the token, it will magic that value into place. With the type hinting, it will find a user with the primary key given in the url.
To use something other than the primary key, you have to add a route binding in RouteServiceProvider.