2017-04-03 76 views
0

PLease,有人,帮助我的过滤器。 我有3个表:投诉,frontend_tag,frontendtags_complaints 我听从由frontend_tag由数据透视表背包crud过滤器

这里过滤投诉是我的过滤代码:

$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'); 
    } 

该过滤器无法正常工作。

+0

你可以在git或这里发布问题https://gitter.im/BackpackForLaravel/Lobby#utm_source=notification&utm_medium=email&utm_campaign=unread-notifications pls? – Indra

回答

1

替换

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

随着

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

的其中施加在相关表状态,在这种情况下frontend_tag。

+0

我得到了:SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'frontend_tag.id'(SQL:select count(*)as'complaint'中的聚合存在(select * from'frontend_tags' inner在'frontend_tags'.'id' ='frontendtags_complaints'.'tag_id'上加入'frontendtags_complaints',其中'frontendtags_complaints'.'complaint_id' ='complaint'.'id'和'frontend_tag'.'id' = 5) id' desc) –

+1

它应该是frontend_tags.id;您为标签表指定了错误的名称,所以我就是这样使用它的。 –

相关问题