集合中的异常.php第 1527 行:此集合实例上不存在属性 [id]



>我收到错误集合中的异常.php第 1527 行:此集合实例上不存在属性 [id]。

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',
                    ''
                );
    }
集合

没有 ID,此集合中的对象具有 ID。因此,您需要使用foreach来迭代数据。但在这种情况下它是多余的,只需执行以下操作:

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

最新更新