Laravel"多对多的多态关系"返回空数组

时间:2016-10-28 10:49:44

标签: php mysql laravel laravel-5.3

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表:

  • ORDER_ID
  • orderable_id
  • orderable_type

我已经在书籍,专辑,订单和商品中创建了一些记录。但是,当我试图从订单中获取书籍时,它会返回一个空数组。没有错误,只有空数组。你知道什么问题可以吗?

0 个答案:

没有答案
相关问题