2016-10-18 18 views
0

どのようにしてmysqlクエリをlaravelクエリに変換できますか? これは、クエリmysqlクエリからlaravelクエリへの変換

SELECT p.*, 
    IF(p.id = wish.product_id,1,0) AS status 
FROM products as p LEFT JOIN `wishlists` as wish ON wish.product_id = p.id and product_id AND wish.user_id = 1 

答えて

0

次のように試してみてくださいです:

$result = \DB::table('products as p') 
    ->select(\DB::raw('IF(p.id = wish.product_id,1,0) AS status')) 
    ->leftJoin('wishlists as wish', function ($join) { 
     $join->on('wish.product_id', '=', 'p.id and product_id') 
     $join->on('wish.user_id', '=', \DB::raw(1)) 
    }) 
    ->get(); 
関連する問題