vendredi 29 juillet 2016

Access authenticated user in route binding (L5.2)

Is it possible to access the authenticated user in a route binding.

Route::bind('account', function($account_id)
{
    dd(auth()->user()); // it's null :(

    $account = App\Models\Account::where('business_id', auth()->user()->business_id)
        ->where('account_id', $account_id)
        ->first()

    return !is_null($account) ? $account : App::abort(404);
});

I've tried grouping the route binding in some auth middleware, no dice - is this a thing? It would be really useful to pull off, to avoid extra validation in the controller.

Help appreciated.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2aiwTkF
via IFTTT

Aucun commentaire:

Enregistrer un commentaire