背包表滤芯 [英] backpack crud filters by pivot table

查看:54
本文介绍了背包表滤芯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人帮我过滤.我有3个表:投诉,frontend_tag,frontendtags_complaints我注意通过frontend_tag过滤投诉

PLease, somebody, help me with filters. I have 3 tables: complaint, frontend_tag, frontendtags_complaints I heed to filter complaints by frontend_tag

这是我的过滤器代码:

$this->crud->addFilter([
            'name' => 'frontendtags',
            'type' => 'select2',
            'label'=> 'FE Tag'
        ], function() {
            return \App\Models\FrontendTags::all()->pluck('name', 'id')->toArray();
        }, function($value) {
            return $this->crud->query->whereHas('frontendtags', function ($q) use ($value) {
                $q->where('tag_id', $value);
            });
        });

这是我的联系代码:

 public function frontendtags()
    {
        return $this->belongsToMany('App\Models\FrontendTags', 'frontendtags_complaints', 'complaint_id', 'tag_id');
    }


过滤器不起作用.


The filter is not working.

推荐答案

替换

$q->where('tag_id', $value);

使用

$q->where('frontend_tag.id', $value);

在相关表(在本例中为frontend_tag)上应用了where条件.

The where condition is applied on the related table, in this case frontend_tag.

这篇关于背包表滤芯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆