Laravel-从4个表导出关系以显示在nova字段中

问题描述

使用nova字段时,我可以传递将出现的关于某些资源的属性数组,以便我可以查看或编辑。主要是这样的:

public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),Text::make('Name')->rules([
                'required','max:255'
            ]),BelongsToMany::make('Customers'),}

当前问题是我有一个相当复杂的关系,其中包括4个表。 表格是:

customers -> id
orders -> id,customer_id
marketing_discount_code -> id
customer_marketing_discount_code -> id,customer_id,marketing_discount_code_id

我要在仪表板上显示的是已应用某些折扣代码的订单。我使用SQL查询实现了以下目的:

select * from `orders` inner join `customers` on `orders`.`customer_id` = `customers`.`id`
inner join `customer_marketing_discount_code` on `customers`.`id` = `customer_marketing_discount_code`.`customer_id`

我目前面临的是如何使用nova fields在仪表板上显示此类输出?通常的方法RelationShip::('method')

我有以下关系

class Customer {
    public function orders()
    {
        return $this->hasMany('App\Order');
    }

    public function marketingdiscountCode()
    {
        return $this->belongsToMany(MarketingdiscountCode::class,'customer_marketing_discount_code');
    }

}
class MarketingdiscountCode {
    public function customers()
    {
        return $this->belongsToMany(Customer::class,'customer_marketing_discount_code');
    }
}

如何在orders添加MarketingdiscountCode方法获取已应用某些折扣代码的所有订单?与前面提到的查询相同。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)