0
我想查詢哪裏isrecurring = 1在我的數據透視表中,但沒有找到現有的解決方案。任何人有任何經驗,以及如何獲得多對多數據透視表中的所有記錄'isrecurring'= 1?Laravel:如何使用數據透視多態多對多
Example.
$enroll->products->where('isrecurring', 1);
but in enrollable pivot table
-> get all records that 'isrecurring' = 1
我的模型(不wherePivot)
Enroll.php
------
public function products(){
return $this->morphedByMany('App\Models\Product', 'enrollable')->withPivot('isrecurring');
}
Product.php
----
public function enrolls(){
return $this->morphToMany('App\Models\Enroll', 'enrollable')->withPivot('isrecurring');
}
我的數據庫
enrolls
-----
id
products
----
id
enrollables
----
enroll_id
enrollable_id
enrollable_type
isrecurring (boolean)
我希望用wherePivot,但似乎沒有工作,無法查詢。
Product.php
----
public function enrolls(){
return $this->morphToMany('App\Models\Enroll', 'enrollable')->withPivot('isrecurring')->wherePivot('isrecurring', '=', 1);
}