让自己纠结于尝试将语句放入 ::raw 查询中:
$rawStatement = "DISTINCT Product";
$product_codes = DB::table('Chemical')
->JOIN('ChemicalTarget', 'Chemical.ChemicalID', '=' , 'ChemicalTarget.ChemicalID')
->select(DB::raw(function($query) with ($rawStatement) {
$query->select(DB::raw($rawStatement));
})
->orderBy('Product', 'asc')
->groupBy('Product')
->lists('Product'); //<-- This is required for existing front end.
最终,我将尝试将其放入该声明中:
CONCAT(Product, ' ', CASE WHEN :stateReg != 'Y' THEN '(not :state reg)' ELSE '' END) as label
和
array('stateReg' => $stateRegistered, 'state' => $state)
和
->orderBy('label', 'asc')
->groupBy('label')
->lists('label');
如果我更换
->select(DB::raw(function($query) with ($rawStatement) {
$query->select(DB::raw($rawStatement));
})
和
->select(DB::raw("DISTINCT Product")
当然有效..
我使用这个链接作为参考来构建我的初始过程,当我添加第二个变量时遇到了障碍,但即使我将它减少到一个,我也无法让 ->lists() 工作。