laravel中连表查询

        $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();

 

posted @ 2019-02-28 16:27  泥土里的绽放  阅读(2515)  评论(0编辑  收藏  举报