Laravel 在构造方法中使用Auth
Laravel版本:5.6* PHP版本:7.2.2 数据库驱动程序和版本:Mysql 5.0.12 说明: 我需要返回已登录用户的contruct方法 复制步骤: 我需要返回登录用户的contruct方法Laravel 在构造方法中使用Auth,laravel,laravel-5.6,Laravel,Laravel 5.6,Laravel版本:5.6* PHP版本:7.2.2 数据库驱动程序和版本:Mysql 5.0.12 说明: 我需要返回已登录用户的contruct方法 复制步骤: 我需要返回登录用户的contruct方法 public function __construct(){ $this->menu = new Menu(); $this->menu->getEnabledMenu(); $this->categories =
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();
}
我尝试了$this->user->Auth::user()->id;但这不起作用
我也试过这个
但我不知道如何访问$this->user 请 我需要帮助
对不起,我的英语是您需要在控制器上定义
$user
属性,如:
class MyController {
// keep a reference to the authenticated user.
public $user;
public function __construct() {
$this->middleware(function ($request, $next){
$this->user = Auth::user();
return $next($request);
});
}
...
}
“但我不知道如何访问$this->user”您是否添加了$user的公共属性?
class MyController {
// keep a reference to the authenticated user.
public $user;
public function __construct() {
$this->middleware(function ($request, $next){
$this->user = Auth::user();
return $next($request);
});
}
...
}