Answers for "laravel route explicit binding"

0

explicit route model binding in laravel

// In RouteServiceProvider
 public function boot()
    {
   		//don't forget import model at the top
        Route::model('unique_key', Blog::class);
        Route::bind('unique_key', function ($value) {
            return Blog::findOrFail($value);
           //return Blog::where('something', $value)->firstOrFail();
        });
   
   //default laravel codes
 }
Posted by: Guest on January-19-2021
0

laravel route explicit binding

public function boot()
{
    parent::boot();

    Route::model('user', App\User::class);
}
Posted by: Guest on July-24-2021
0

laravel route implicit binding

Route::get('api/users/{user}', function (App\User $user) {
    return $user->email;
});
Posted by: Guest on July-24-2021

Browse Popular Code Answers by Language