私は、次のリポジトリProducts
を持っており、各製品は、私が達成しようとしています何Categories
と多くのBidders
LaravelリポジトリwhereHas - 複数
多くを持つことができますが
$products = Products::whereHas('categories', function ($category) {
})->whereHas('bidders', function ($bidder) {
})->get();
この(リポジトリがなければ)以下れますしかし、私はリポジトリが適切に配置され、依然としてwhereHas
クエリを実行できるようにしようとしていますので、私のリポジトリではメソッドを作成しました:
public function whereHas($attribute, \Closure $closure = null)
{
return $this->model->whereHas($attribute, $closure);
}
これはうまく動作しますが、私は複数使用している場合のに対し、私のメインのクエリでそれらのいずれかを使用していた場合にのみ:
$products = $this->products->whereHas('categories', function ($category) {
$category->where('id', '=', 1);
})->whereHas('bidders', function($bidders) {
})->get();
私は、次のエラーを取得しています:
Unknown column 'has_relation'
Column not found: 1054 Unknown column 'has_relation' in 'where clause' (SQL: select * from
products
where exists (select * fromcategories
inner joinproducts_categories
oncategories
.id
=products_categories
.categories_id
whereproducts
.id
=products_categories
.products_id
andid
= 1) and (has_relation
= sections))
私が見ている問題は、最初のwhereHas
のアイテムのコレクションを返すことです。つまり、2番目のアイテムを計算できません。私が間違っているところへのアイデアは?