aman
aman

Reputation: 75

Exception in Collection.php line 1527: Property [id] does not exist on this collection instance

i m getting error Exception in Collection.php line 1527: Property [id] does not exist on this collection instance.

public function index()
    {
        $response=array();
        $data = MyList::all();
        $response['id']=$data->id;
        $response['name']=$data->name;
        $response['password']=$data->password;
        $response['city']=$data->city;   
        return ResponseClass::prepareResponse(
                    $response,
                    'success',
                    ''
                );
    }

Upvotes: 0

Views: 622

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163788

A collection doesn't have an ID, objects in this collection have IDs. So, you need to use foreach to iterate over the data. But in this case it's redundant, just do something like this:

public function index()
{ 
    return ResponseClass::prepareResponse(MyList::all(), 'success');
}

Upvotes: 1

Related Questions