【发布时间】:2018-07-03 11:33:43
【问题描述】:
我是 Laravel 新手。我使用的是 Laravel 5.5 版
如果我尝试使用邮递员登录。我得到“尝试获取非对象的属性 'id'”错误。错误行是
private $client;
public function __construct(){
$this->client = Client::find(1);
}
public function login(Request $request){
$this->validate($request, [
'username' => 'required',
'password' => 'required'
]);
return $this->issueToken($request, 'password'); // this line has error
}
issueToken函数
public function issueToken(Request $request, $grantType, $scope = ""){
$params = [
'grant_type' => $grantType,
'client_id' => $this->client->id,
'client_secret' => $this->client->secret,
'scope' => $scope
];
if($grantType !== 'social'){
$params['username'] = $request->username ?: $request->email;
}
$request->request->add($params);
$proxy = Request::create('oauth/token', 'POST');
return Route::dispatch($proxy);
}
我在注册时遇到了同样的错误。但是我的用户成功注册了 500 错误(尝试获取非对象的属性 'id')
【问题讨论】:
-
这意味着
$this->client是null -
对不起,我忘记了。添加了 $client 变量
-
显示 dd($this->client)
-
null @Sohel0415 我如何填写 $this->client.我用视频学习 laravel。我对视频应用相同的操作。有什么问题?
-
您有 id 为 1 的客户吗??
标签: php mysql laravel laravel-5