【发布时间】:2019-01-19 21:01:48
【问题描述】:
我有一个雄辩的查询问题。 当我运行查询时,我得到了未定义的变量:ccid
我已经通过函数通过了ccic
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'));
}
有人有想法吗? 非常感谢
【问题讨论】:
-
->join('users', function ($join) use($ccid) {...}) 必须将变量传入作用域。
标签: laravel eloquent laravel-5.7