我正在尝试针对我的用户ID保存我的数据,但是我收到了此错误。
我的代码是:
\App\Keys::create([
$user = \Illuminate\Support\Facades\Auth::user(),
'user_id' => $user,
'accessTokenKey' => $accessTokenKey,
'accessTokenSecret' => $accessTokenSecret
]);
return 'You have successfully granted';
我收到错误user_id没有默认值,当我通过Auth :: user() - > id时,它说试图获取非对象id的属性。
任何帮助将不胜感激!
答案 0 :(得分:0)
那是因为您没有任何经过身份验证的用户
if(Auth::check()){
\App\Keys::create([
$user = \Illuminate\Support\Facades\Auth::user(),
'user_id' => Auth::id(),
'accessTokenKey' => $accessTokenKey,
'accessTokenSecret' => $accessTokenSecret
]);
}else{
//logged in the user or
return 'User is not logged in ';
}