如何将SQL查询转换为原始查询

时间:2018-05-09 12:12:55

标签: laravel

SELECT fp.id, fp.name, fp.slug, fp.status, fc.name, fc.slug as category_slug, fp.approved, ff.filepath, fdp.product_id,fdp.type, fdp.sku, fdp.regular_price, fdp.sale_price, fp.created_at, fp.updated_at 
FROM `foduu_products` fp 
       JOIN `foduu_details_product` fdp ON fp.id= fdp.product_id 
       JOIN `foduu_category_product` fcp ON fp.id = fcp.product_id
       JOIN `foduu_filemanager` ff ON fp.filemanager_id = ff.id
       JOIN `foduu_categories` fc ON fcp.category_id = fc.id
WHERE fc.slug= "microsoftheadphonesadaptersmotherboardswebcam" 
      AND fp.approved = 1 
      AND fp.status = 1

1 个答案:

答案 0 :(得分:0)

此代码应根据您的逻辑运行:

  $match = ['fc.slug' => 'microsoftheadphonesadaptersmotherboardswebcam', 'fp.approved' => '1', 'fp.status'=>'1'];

    $result = DB::table('foduu_products as fd')
                 ->join('foduu_details_product as fdp','fp.id','=','fdp.product_id')
                 ->join(......
                        .............
                 ->where($match)
                 ->select('fp.id', 'fp.name', ...................)
                 ->get();