Laravel 之 Left Join 方法使用

举例子如下:

$models = static::where('user_id', $userId)->leftJoin('product_gift', function ($join) {
    $join->on('product_gift_exchange_order.prd_id', '=', 'product_gift.prd_id');
    $join->on('product_gift_exchange_order.gift_code', '=', 'product_gift.gift_code');
})->orderBy('product_gift_exchange_order.autokid', 'DESC')->get([
    'product_gift_exchange_order.autokid',
    'product_gift_exchange_order.ctime',
    'product_gift_exchange_order.exchange_amount',
    'product_gift.gift_name',
]);


comments powered by Disqus