I am getting this returned to me:
{
"GROUP_CONCAT(DISTINCT(CONCAT(\"MAX(IF(pa.printer = \"\"\", printer, \"\"\", pa.printer, NULL)) AS \", printer)))":
"MAX(IF(pa.printer = \"JP4-3\", pa.printer, NULL)) AS JP4-3,MAX(IF(pa.printer = \"JP4-1\", pa.printer, NULL)) AS JP4-1,MAX(IF(pa.printer = \"JP4-2\", pa.printer, NULL)) AS JP4-2,MAX(IF(pa.printer = \"B3\", pa.printer, NULL)) AS B3,MAX(IF(pa.printer = \"A2\", pa.printer, NULL)) AS A2"
}
I want to get the value of this but just the string. I can't get it out of the {}. This should be so simple but cant find an answer anywhere.
BELOW IS JUST REFERENCE TO WHAT I AM DOING
The main goal is a MySQL pivot table. Takes 2 calls but I am OK with that.
$listQuery = PrintJob::select(DB::raw('GROUP_CONCAT(DISTINCT(CONCAT("MAX(IF(pa.printer = """, printer, """, pa.printer, NULL)) AS ", printer)))'))->get();
This is returning the result above:
$json = $listQuery[0];
Then going to use it in this query
$data = PrintJob::select(DB::raw('DATE(calendar.datefield) as date'), DB::raw('SUM(print_jobs.quantity) as sum'), DB::raw($listQuery))
->leftJoin('mo_numbers', 'mo_numbers.mo_id', '=', 'print_jobs.mo_id')
->rightJoin('calendar', 'calendar.datefield', '=', 'print_jobs.job_date')
->whereDate('calendar.datefield', '>=', date($from))
->whereDate('calendar.datefield', '<=', date($to))
->groupBy('date')
->toSql();
//->get();