1 回答

TA贡献1797条经验 获得超4个赞
尝试这个:
public function index()
{
try {
$data = new ProductCollection(Product::with('user')->all());
return response()->json($data);
} catch (\Throwable $th) {
return response()->json($th);
}
}
编辑:
public function toArray($request) {
return [
'id' => $this->id,
'nama_produk' => $this->nama_produk,
'user_id' => $this->user_id,
'user' => $this->user,
'description' => $this->description
]
}
或者
public function toArray($request) {
return [
'id' => $this->id,
'nama_produk' => $this->nama_produk,
'user_id' => $this->user,
'description' => $this->description
]
}
- 1 回答
- 0 关注
- 93 浏览
添加回答
举报