Laravel: Auth::user()-gt;id trying to get a property of a non-object(Laravel:Auth::user()-gt;id 试图获取非对象的属性)
问题描述
当我提交表单以添加用户时,我收到以下错误尝试获取非对象的属性",错误显然在第一行:Auth::user()->id以下内容:
I'm getting the following error "trying to get a property of a non-object" when I submit a form to add a user, the error is apparently on the first line: Auth::user()->id of the following:
$id = Auth::user()->id;
$currentuser = User::find($id);
$usergroup = $currentuser->user_group;
$group = Sentry::getGroupProvider()->findById($usergroup);
$generatedPassword = $this->_generatePassword(8,8);
$user = Sentry::register(array('email' => $input['email'], 'password' => $generatedPassword, 'user_group' => $usergroup));
$user->addGroup($group);
有什么想法吗?我已经搜索了一段时间,我看到的一切都说这应该可以正常工作.我的用户使用 Sentry 2 身份验证包登录.
Any ideas? I've searched for a while and everything I see says this should work fine. My user is logged in using the Sentry 2 authentication bundle.
推荐答案
如果你使用 Sentry
用 Sentry::getUser()->id 检查登录用户
代码>.您得到的错误是 Auth::user()
返回 NULL 并尝试从 NULL 获取 id 因此错误 trying to get a property from a non-object
.
If you are using Sentry
check the logged in user with Sentry::getUser()->id
. The error you get is that the Auth::user()
returns NULL and it tries to get id from NULL hence the error trying to get a property from a non-object
.
这篇关于Laravel:Auth::user()->id 试图获取非对象的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel:Auth::user()->id 试图获取非对象的属性


- PHP Count 布尔数组中真值的数量 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01