Back

Use Auth in construct method


Laravel Version: 5.6.*

PHP Version: 7.2.2

Database Driver & Version: Mysql 5.0.12

Description:

logged user in contruct method return null

Steps To Reproduce: I need return logged user in contruct method,

public function __construct(){

	$this->menu = new Menu();

	$this->menu->getEnabledMenu();

	$this->categories = $this->
	menu::with('children')->
	where('parent_id','=',0)->
	whereIn('id', [8,9,7])->
	orderBy('position', 'asc')->
	get();
}

i tried with $this->user->Auth::user()->id; but this doesn't work

i also tried this

https://laravel-news.com/controller-construct-session-changes-in-laravel-5-3

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

        return $next($request);
    });

but i I do not know how to access $this->user

please i need help

sorry for my english


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us