に生のクエリを変換する私はMySQLの作業台でクエリを作成しているlaravel
product_categories
id | product_category
---------------------
1 | ABC
2 | DBC
3 | EBA
store_product_categories
id | category_id | store_id
------------------------
1 | 2 | 11
2 | 1 | 11
3 | 3 | 11
このスキーマを持って
SELECT pc.* FROM product_categories pc LEFT JOIN store_product_categories spc ON pc.category = pc.id AND spc.store_id = 11 WHERE spc.category IS NULL;
store_product_categories
に存在しないproduct_categories
テーブルからこれらのカテゴリを実際にすべて取得します。
今、私はこれを構築する方法を本当に混乱していますがLaravel Eloq ..です
私はこれを試してみました。
$exclusive_categories = Product_category::join('store_product_categories','store_product_categories.category_id','=','product_categories.id')
->where('store_product_categories.store_id','=',session('store_id'))
->where('store_product_categories.category_id','=','NULL')->get();
しかし、これは私が使用すると、2つの異なる列に参加しているので、あなたが機能/クロージャを通じてそれを渡す必要が
動作しません!クエリを徹底的にチェックしてください!私の質問 – Alex
あなたの質問を実行しようとしましたか? 返されたデータは何ですか? $ exclusive_categories = PRODUCT_CATEGORY :: leftJoin( 'store_product_categories'、 'store_product_categories.category_id'、 '='、 'product_categories.id') - >( 'store_product_categories.store_id'、 '='、セッション( 'STORE_ID '))) - > whereNull(' store_product_categories.category_id ') - > get(); –