0

I have a problem with a eloquent query. When i run the query i get back Undefined variable: ccid

i have pass the ccic via function

public function index($category)
{
    $currentuser = auth()->user();
    $ccid = $currentuser->clientcat_id;

    $products = DB::table('products')
        ->join('resomes', 'products.pricingcat_id', '=', 'resomes.pricingcat_id')
        ->join('users', function ($join) {
            $join->on('resomes.clientcat_id', '=', 'users.clientcat_id')
            //->where('users.clientcat_id', '=', 1);
            ->where(function($q) use($ccid){ 
                $q->where('users.clientcat_id', '=', $ccid);
            }
            );
        })
        ->select('products.*', 'resomes.discount', DB::raw('(products.price - (products.price * (resomes.discount/100))) as cPrice'))
        ->where('products.ccat_id', '=', $category)
        //->where(function($q) use($category){ $q->where('products.ccat_id', '=', $category);})
        ->orderBy('products.ccat_id', 'ASC')
        ->orderBy('products.price', 'ASC')
        ->paginate(config('pelma.products_list_pagination'));

    //print_r($products);
    return view('client.products.list', compact('products'));
}

Anyone have an idea? Thank you very much

2 Answers2

0

You didn't pass $ccid to

->join('users', function ($join)

you have to use $ccid to this function also.

0

You can do someting like this

->join('users', function ($join) use ($ccid) {

and explaination is here In PHP, what is a closure and why does it use the "use" identifier?

Fil
  • 8,225
  • 14
  • 59
  • 85