我在我的项目中使用Metable创建订单的元数据但是我有一个问题我想要具有相同电子邮件的团体订单这是可满足的表格图片:image 1 image 2
我需要这样的代码可以工作:)
Order::whereHas( 'meta', function($query) {
$query->where("key" , "gmail");
})->groupBy('meta.value')->get();
这是由订单模型中的特征'use Metable'调用的元关系:
public function meta(): MorphMany
{
return $this->morphMany($this->getMetaClassName(), 'metable');
}
谢谢
首先获得所有订单,然后通过电子邮件分组:
Order::with('meta')
->whereHas( 'meta', function($query) {
$query->where("key" , "gmail");
})
->get()
->groupBy(function ($order) {
return $order->meta->value;
});