laravel route explicit binding

Solutions on MaxInterview for laravel route explicit binding by the best coders in the world

showing results for - "laravel route explicit binding"
Leyna
14 Jan 2016
1// In RouteServiceProvider
2 public function boot()
3    {
4   		//don't forget import model at the top
5        Route::model('unique_key', Blog::class);
6        Route::bind('unique_key', function ($value) {
7            return Blog::findOrFail($value);
8           //return Blog::where('something', $value)->firstOrFail();
9        });
10   
11   //default laravel codes
12 }
Theo
19 Oct 2016
1public function boot()
2{
3    parent::boot();
4
5    Route::model('user', App\User::class);
6}
Chantelle
14 Apr 2017
1Route::get('api/users/{user}', function (App\User $user) {
2    return $user->email;
3});