close

[Solved] Laravel 5.5 Trying to get property ‘id’ of non-object

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Laravel 5.5 Trying to get property ‘id’ of non-object in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Laravel 5.5 Trying to get property ‘id’ of non-object Error Occurs?

Today I get the following error Laravel 5.5 Trying to get property ‘id’ of non-object in php.

How To Solve Laravel 5.5 Trying to get property ‘id’ of non-object Error ?

  1. How To Solve Laravel 5.5 Trying to get property 'id' of non-object Error ?

    To Solve Laravel 5.5 Trying to get property 'id' of non-object Error Make sure you have record in database table for User model with id = 1. When you're using User::find(1) Laravel tries to get this record from database, if record is absent this will return null

  2. Laravel 5.5 Trying to get property 'id' of non-object

    To Solve Laravel 5.5 Trying to get property 'id' of non-object Error Make sure you have record in database table for User model with id = 1. When you're using User::find(1) Laravel tries to get this record from database, if record is absent this will return null

Solution 1

In your issueToken() method-

$client = Client::find(1);
if($client!=null){
     $params = [
       'grant_type' => $grantType,
       'client_id' => $client->id,
       'client_secret' => $client->secret,           
       'scope' => $scope
    ];
}else{
    $params = [
       'grant_type' => $grantType,
       'client_id' => null,
       'client_secret' => null,           
       'scope' => $scope
    ];
}

Solution 2

Make sure you have record in database table for User model with id = 1. When you’re using User::find(1) Laravel tries to get this record from database, if record is absent this will return null

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment