0
我設置流明與學說(laravel-主義/ ORM)流明+主義的findAll返回空對象數組
當我嘗試獲取結果(即$這個 - > EM-> getRepository(學生::類) - > findAll();)在一個HTTP路由,我得到一個空的大括號數組。
如何使序列化正確運行?
我設置流明與學說(laravel-主義/ ORM)流明+主義的findAll返回空對象數組
當我嘗試獲取結果(即$這個 - > EM-> getRepository(學生::類) - > findAll();)在一個HTTP路由,我得到一個空的大括號數組。
如何使序列化正確運行?
首先,你需要Illuminate\Support\Collection
類,像包裹你的結果:
use Illuminate\Support\Collection;
return Collection::make(
$this->em->getRepository(Student::class)->findAll()
);
之後,通過將其分配到Illuminate\Contracts\Support\Arrayable
合同修改Student
類。
use Illuminate\Contracts\Support\Arrayable;
class Student implements Arrayable
{
// Your code here
}
接下來,你應該實現toArray
方法您Student
類: