lundi 22 février 2016

LARAVEL $router->bind for only backend(admin)

In RouteServiceProvider I have:

$router->bind('user', function ($value) {
    return app(UserInterface::class)->findOrFail($value);
});

and url for admin is "/admin/user/1".

but for frontend url is "/user/username"

So I want to check if this is "admin" or "frontend" url and for admin bind user but for frontend don't bind user:

$adminRoute = //check if this is admin or frontend url ("/admin/user/1" or "/user/username")

if($adminRoute){
    $router->bind('user', function ($value) {
        return app(UserInterface::class)->findOrFail($value);
    });
}else{
    //nothing
}

PS. I don't want change findOrFail() function to find user by username I want disable binding for non admin urls.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire