php – Laravel Auth ::在其他控制器中找不到用户
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – Laravel Auth ::在其他控制器中找不到用户,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1750字,纯文字阅读大概需要3分钟。
内容图文
![php – Laravel Auth ::在其他控制器中找不到用户](/upload/InfoBanner/zyjiaocheng/780/ff6fe0108826426a9878264b7547d62f.jpg)
当用户注册时,会向用户发送电子邮件,其中包含链接到此功能的激活链接(auth_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之前使用__construct实例化公司控制器时,对象companyController在进行Auth :: login()调用之前就存在了.
内容总结
以上是互联网集市为您收集整理的php – Laravel Auth ::在其他控制器中找不到用户全部内容,希望文章能够帮你解决php – Laravel Auth ::在其他控制器中找不到用户所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。