vendredi 29 juillet 2016

Laravel 5.2 - access authenticated user in route binding

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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire