Php Laravel Auth::在其他控制器中找不到用户
当用户注册时,会向用户发送一封电子邮件,其中包含一个激活链接(验证码),该链接链接到此功能:Php Laravel Auth::在其他控制器中找不到用户,php,mysql,laravel,Php,Mysql,Laravel,当用户注册时,会向用户发送一封电子邮件,其中包含一个激活链接(验证码),该链接链接到此功能: public function confirmUser($authentication_code) { if (!$authentication_code) { return 'auth code not found!'; } $user = User::where('authentication_code', '=', $authentication_code
public function confirmUser($authentication_code)
{
if (!$authentication_code) {
return 'auth code not found!';
}
$user = User::where('authentication_code', '=', $authentication_code)->first();
if (!$user) {
return 'user not found!';
}
$user->active = 1;
$user->save();
Session::put('user_id', $user->id);
Auth::login($user);
return view('user.setpassword', ['user' => $user]);
}
因此,用户将登录
现在我的问题来了。通过UserConstructor
它将导致CompanyController
//UserController
public function __construct(User $user, CompaniesController $companies, UserTypeController $userType, AttributeController $attributes)
{
$cid = Auth::user()->company_id;
if (Auth::user()->usertype_id == 7) {
$this->user = $user;
}
else
{
$array_company_ids = $companies->getCompany_ids($cid);
$this->user = $user->whereIn('company_id', $array_company_ids);
}
}
//CompanyController
public function __construct(Company $company)
{
if (Auth::user()->usertype_id == 7) {
$this->company = $company;
} else {
$this->company_id = Auth::user()->company_id;
$this->company = $company->Where(function ($query) {
$query->where('id', '=', $this->company_id)
->orWhere('parent_id', '=', $this->company_id);
});
}
$this->middleware('auth');
$page_title = trans('common.companies');
view()->share('page_title', $page_title);
}
这导致了这个错误:
当我在CompanyController中执行Auth::check()
时,它会返回false,因此它会在这个过程中注销用户,出了什么问题
(confirmUser中的Auth::check()将给出true作为结果)根据我所读的内容。您正在使用参数CompanyController实例化UserController 此实例化在您实际发送Auth::login()调用之前完成
当您在
userController
上运行confirmUser
之前,使用\uu构造实例化公司控制器时,在调用Auth::login()
之前,对象companyController就存在了。我确实用一个隐藏的输入字段发送了它。试着这样做:
<input id="email" type="hidden" name="email" value="{{ Auth::user()->email }}" required>
我的很好用。这是什么usertype\u id
这是你用户表上的一个共谋?usertype 1->一个客户,2->代理,3->员工,(7->管理员)等等,仅仅是一个用户类型(CMS)就好像是一个会话问题;Auth::check()在CompanyController的开头说了什么?您有什么会话驱动程序?它将返回false
,我使用elount
会话是什么样子的<代码>变量转储(\Request::session()->all())代码>