Как сделать это предложение в построителе запросов - PullRequest
0 голосов
/ 03 октября 2019

У меня есть вопрос, мне нужно сделать этот запрос в построителе запросов:

SELECT
ps_orders.id_order,
ps_customer.firstname,
ps_customer.lastname,
ps_customer.email,
ps_address.address1,
ps_address.postcode,
ps_address.city,
ps_address.phone_mobile,
ps_orders.id_order,
ps_orders.reference,
ps_order_detail.product_name,
ps_order_detail.product_quantity,
ps_shop.name AS tienda,
ps_carrier.name AS transportista
FROM
ps_customer
INNER JOIN ps_address ON ps_customer.id_customer = ps_address.id_customer
INNER JOIN ps_orders ON ps_address.id_customer =              
ps_orders.id_customer AND ps_orders.id_address_delivery = 
ps_address.id_address
INNER JOIN ps_order_detail ON ps_orders.id_order = 
ps_order_detail.id_order
INNER JOIN ps_shop ON ps_order_detail.id_shop = ps_shop.id_shop                            
INNER JOIN ps_carrier ON ps_orders.id_carrier = ps_carrier.id_carrier                            
WHERE
ps_orders.id_order =54

Я сделал этот запрос в построителе запросов:

$naviones=DB::connection('naviones')->table('ps_customer')
                ->join('ps_address','ps_customer.id_customer','=','ps_address.id_customer')
               ->join('ps_orders','ps_address.id_customer','=','ps_orders.id_customer')
                ->join('ps_order_detail','ps_orders.id_order','=','ps_order_detail.id_order')
                ->join('ps_shop','ps_order_detail.id_shop','=','ps_shop.id_shop')
                ->join('ps_carrier','ps_orders.id_carrier','=','ps_carrier.id_carrier')
                ->select('ps_orders.id_address_delivery','ps_orders.id_order','ps_customer.firstname','ps_customer.lastname','ps_customer.email','ps_address.address1',
                    'ps_address.postcode','ps_address.city','ps_address.phone_mobile','ps_orders.id_order','ps_orders.reference',
                    'ps_order_detail.product_name','ps_order_detail.product_quantity','ps_shop.name as tienda','ps_carrier.name as transportista')
                ->where('ps_orders.id_order','=',$idpedido)->get();

Мой вопрос: Как я могусделать для этого раздела запроса?

INNER JOIN ps_orders ON ps_address.id_customer =              
ps_orders.id_customer AND ps_orders.id_address_delivery = 
ps_address.id_address

Я надеюсь, что ваша воля может помочь мне. Спасибо.

1 Ответ

1 голос
/ 03 октября 2019

Вы можете использовать join что-то вроде этого

->join('table2 AS b', function($join){
        $join->on('a.field1', '=', 'b.field2')
        ->where('b.field3', '=', true)
        ->where('b.field4', '=', '1');
})

, если вы не хотите сравнивать, тогда вы можете использовать несколько функций "on", как показано ниже

$query->join('ps_orders', function($join)
 {
   $join->on('ps_orders.id', '=', 'ps_address.id_customer')
        ->on('ps_orders.id_address_delivery', '=', 'ps_address.id_address')

 });
...