簡體   English   中英

Laravel:選擇具有范圍的樞軸列

[英]Laravel: select pivot column with scope

我想顯示詳細信息,這很簡單! 我在模型(Estate)中使用ScopeFilter函數:

public function scopeFilter($query, $zone = null,  $type = null) {
    $query->whereHas('types',function ($query) use ($type) {
        $query->whereTitle($type);
    })->whereHas('zone',function ($query) use ($zone) {
            $query->whereSlug($zone);
    });
    return $query;
}`enter code here`

是我的控制器(房地產控制器):

$estates = Estate::filter($zone,$type)->latest()->paginate(12);

這是我的關系:

public function types()
{
    return $this->belongsToMany(Type::class)->withPivot('slug');
}

我的多對多表中還有一個附加列,例如:

estate_id| type_id |   slug  |
------------------------------
    a    |    b    |   a_b   |
    c    |    d    |   c_d   |

我所做的一切都很好, 只需要顯示詳細信息以及多對多表中“子彈”列上的位置。

whereHas('types',function ($query) use ($type) { $query->where('estate_type.slug',$type); }) 

找到它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM