O
O
ObehanProger2019-03-01 16:11:43
Laravel
ObehanProger, 2019-03-01 16:11:43

How to define authenticated user in Laravel controller constructor?

Found in the documentation that since version 5.3 you can't use the Auth facade to get the authenticated user in the controller's constructor, but only with a Closure-based proxy. But how to do it? Show me with an example. The code below gives an error that the $user object does not exist:
public function __construct(){
$this->user=auth()->user();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2019-03-01
@ObehanProger

https://laravel.com/docs/5.3/upgrade "Controllers" section. And it's not all about the façade.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question