laravel中連表查詢
阿新 • • 發佈:2019-02-28
attr span clas _id spa pre lis and model
$skuList = ProductSkuModel::selectRaw(‘product_skus.id as sku_id, product_skus.code as code, product_skus.wname as sku_name, product_skus.stocks as stocks, if(`product_skus`.`status`=1,\‘上架\‘,\‘下架\‘) as status, brands.name as brand, product_attributes.attribute_name as basic_attribute, product_attributes.attribute_value_name as basic_attribute_name, sku_attributes.attribute_name as price_attribute, sku_attributes.attribute_value_name as price_attribute_name‘) ->leftJoin(‘product_attributes‘, ‘product_skus.product_id‘, ‘=‘, ‘product_attributes.product_id‘) ->leftJoin(‘sku_attributes‘, ‘product_skus.id‘, ‘=‘, ‘sku_attributes.sku_id‘)->leftJoin(‘brands‘, ‘product_skus.brand_id‘, ‘=‘, ‘brands.id‘) ->where(‘sku_attributes.status‘, 1) ->where(‘product_attributes.status‘, 1) ->get()->toArray();
laravel中連表查詢