一张表中的 Laravel 多个变形关系

时间:2021-05-06 10:52:20

标签: php laravel laravel-8 php-5.3

我在 Laravel 中遇到问题。我在一张表中创建了多个变形。

table structure 
table_name : morphicable
id: 
model_id:       eg: '1'
model_type:     eg 'model/comment'

model_one_id:   eg: '1'
model_one_type: eg 'model/order'

在上面的关系中,我们可以将数据从评论保存到订单,从订单到评论,就像多到多一样。

现在的问题是如何从一种 ORM 方法中获取这两种数据。就像我们有时在模型类型中保存注释,在模型类型中保存一些时间。

我想一次性从两个模型中获取数据。

public function morphicable(): MorphMany
{
    return $this->morphMany(morphicable::class, 'model');
}

0 个答案:

没有答案