Album.php
/**
* Get all of the orders for the album.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function orders()
{
return $this->morphToMany(Order::class, 'orderable');
}
book.php中
/**
* Get all of the orders for the book.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function orders()
{
return $this->morphToMany(Order::class, 'orderable');
}
Order.php
/**
* Get all of the albums that are assigned this order.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function albums()
{
return $this->morphedByMany(Album::class, 'orderable');
}
/**
* Get all of the books that are assigned this order.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function books()
{
return $this->morphedByMany(Book::class, 'orderable');
}
Orderables表:
我已经在书籍,专辑,订单和商品中创建了一些记录。但是,当我试图从订单中获取书籍时,它会返回一个空数组。没有错误,只有空数组。你知道什么问题可以吗?