Answer the question
In order to leave comments, you need to log in
Why is the authenticated user no longer defined in __construct?
I made a private variable, defined a value in the constructor, at first it worked, then it stopped for no reason, maybe I wrote something wrong?
And if in the method I prescribe what is equal, then everything works fine
class PostController extends BaseController{
private $auth;
public function __construct() {
parent::__construct();
$this->auth = Auth::user();
}
public function index() {
// $this->auth = Auth::user();
dd($this->auth);
Answer the question
In order to leave comments, you need to log in
Decided in this way
In the controller from which PostController is inherited, the controller added
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
abstract class BaseController extends Controller
{
public function authUser()
{
return Auth::user();
}
}
$this->authUser()
with all the consequences
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question