K
K
koida_yuri2017-04-12 15:49:33
Laravel
koida_yuri, 2017-04-12 15:49:33

What is the stage of user authentication in Laravel?

I'm trying to write some conditions for an authorized user, such as access rights to the controller. I am writing a check in the controller constructor, but when debugging, I notice that $request->user() === null. Thus already in an executable method everything sees. How to describe these conditions for the entire controller without adding this condition in each method?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
lxfr, 2017-04-12
@lxfr

7c737d08289348fc864fb5afb64d1b1d.jpg

J
jlay, 2017-04-12
@jlay

In the constructor, you can get it only through an intermediary.

$this->middleware(function ($request, $next)
{
        $this->user= Auth::user();

        return $next($request);
});

V
Victor, 2017-04-12
@v_decadence

Dock
Section Session In The Constructor

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question