Почему не работает Auth в laravel?

Добрый день, всем.
Проблема такова, обновил Laravel до 5.3 и не работает часть кода

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


Middleware видят что юзер авторизирован, а
Auth::user() показывает null
в чем может проблема?
  • Вопрос задан
  • 1107 просмотров
Решения вопроса 1
DJZT
@DJZT
Laravel - code for you
Вы это используете в конструкторе контроллера?

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:
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы