in my case, i want to display users and orders completed by each user, orders have status i get $status from input form here is my code
$orders = DB::table('user_profiles')
        ->leftJoin('orders', function($join){
            $join->on('user_profiles.id','=','orders.id_user')
                ->where('orders.status','=',$status);
        })
        ->selectRaw('user_profiles.*, count(orders.id_user) as order_try_count')
        ->groupBy('user_profiles.id')
        ->orderBy('order_try_count',$order)
        ->paginate(15);
but i get undefined variable status, what should i do to solve this problem ?, thank you
Yoo need to pass variables into closure using use construction like so:
->leftJoin('orders', function($join) use ($status) {
instead of
->leftJoin('orders', function($join) {
Reference: anonymous functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With