vendredi 5 juin 2020

Select element in where clause using join - Laravel

I have a query in which I am getting data using joins on multiple tables. The problem is in join of "vendor_products" table. I want to get data from it using a where clause and i am giving the value of vendor_id from the select element. If I hard code the value the data is coming but if I used the "orders_vendor_id", the query did not worked.

Order::select(
        'orders.vendor_id as vendor_id',
        'order_items.product_id as product_id',
        'vendor_products.stock_id as stock_id',
        'vendors.stock as stock',
    )
    ->join('order_items',function($join){
        $join->on('order_items.orders_id', '=','orders.id')
        ->whereNotNull('final_delivery_price');
    })
    ->join('vendor_products',function($join){
        $join->on('vendor_products.product_id', '=','order_items.product_id')
        ->where('vendor_products.vendor_id', 'orders.vendor_id');
    })
    ->join('vendors',function($join){
        $join->on('vendors.id', '=','orders.vendor_id');
    })
    ->where('orders.status', 'delivered')
    ->where('orders.created_at','>=', Carbon::now()->subDays(14))
    ->groupBy('orders.vendor_id','order_items.product_id','vendor_products.vendor_stock_id','vendors.vendor_stock')
    ->orderBy('order_items.product_id');


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3czG1S0
via IFTTT

Aucun commentaire:

Enregistrer un commentaire