Got myself tangled up trying to put a statement into a ::raw query:
$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.
Eventually I'm going to try to put this into that statement:
CONCAT(Product, ' ', CASE WHEN :stateReg != 'Y' THEN '(not :state reg)' ELSE '' END) as label
with
array('stateReg' => $stateRegistered, 'state' => $state)
and
->orderBy('label', 'asc')
->groupBy('label')
->lists('label');
If I replace
->select(DB::raw(function($query) with ($rawStatement) {
$query->select(DB::raw($rawStatement));
})
with
->select(DB::raw("DISTINCT Product")
Of course it works..
I was using this link as reference to build my initial process, hit a snag when I added a 2nd variable, but even when I reduced it to one, I could not get ->lists() to work.