1 回答

TA貢獻1797條經(jīng)驗 獲得超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 關(guān)注
- 110 瀏覽
添加回答
舉報