V
V
Vladislav Nagorny2016-09-26 14:54:09
Laravel
Vladislav Nagorny, 2016-09-26 14:54:09

Why doesn't Auth work in laravel?

Good day to all.
The problem is this, I updated Laravel to 5.3 and part of the code does not work

use Illuminate\Support\Facades\Auth;
 public function __construct()
{
 $this->user = Auth::user();
view()->share('user', $this->user);
}

Middleware sees that the user is authorized, and
Auth::user() shows null
, what could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Pochepko, 2016-09-26
@esvils

Are you using this in the controller's constructor?
https://laravel.com/docs/5.3/upgrade
Session In The Constructor
In previous versions of Laravel, you could access session variables or the authenticated user in your controller's constructor. This was never intended to be an explicit feature of the framework. In Laravel 5.3, you can't access the session or authenticated user in your controller's constructor because the middleware has not run yet.
As an alternative, you may define a Closure based middleware directly in your controller's constructor. Before using this feature, make sure that your application is running Laravel 5.3.4 or above:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question