본문 바로가기
MySql

MySQL Laravel 5.5 비 객체의 'id'속성을 얻으려고합니다.

by 베이스 공부 2020. 10. 20.
반응형

저는 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);

}

Register에서 동일한 오류가 발생했지만 내 사용자가 500 오류로 성공적으로 등록했습니다 (비 개체의 'id'속성을 얻으려고 시도 중).

 

해결 방법

 

레코드가 있는지 여부를 확인해야합니다.

변경 :

$this->client = Client::find(1);

받는 사람 :

$this->client = Client::findOrFail(1);

문서 :


 

참조 페이지 https://stackoverflow.com/questions/48422199

 

 

반응형

댓글