控制器中的Laravel Auth用户ID [英] Laravel Auth user id in controller
本文介绍了控制器中的Laravel Auth用户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Laravel样板.我正在尝试获取已登录用户的user_id
.我收到以下错误:
I am using the Laravel boilerplate. I'm trying to get the user_id
of the signed in user. I am getting the following error:
找不到类'App \ Http \ Controllers \ Frontend \ Auth'
Class 'App\Http\Controllers\Frontend\Auth' not found
这是电话
$user = Auth::user();
然后我尝试使用以下方法获取ID:
Then I try to get the id using:
$user->id
我想念什么?
推荐答案
您需要在控制器中使用Auth外观;
You need to use the Auth facade in the controller;
在类定义之前添加此行.
add this line just before class definition.
use Auth;
这篇关于控制器中的Laravel Auth用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文