$citizenship_2012 = Citizenship::select('provinces', 'year2012 AS measure')->get();
I want to display one of the column names as it is. The column/attribute name is year2012
, but I want to display it as category =>year2012
, so I'm trying to get the column name below.
Also, I want to merge it with the above select
query, in which other attributes provide its value
name.
// citizenships table
$years = Schema::getColumnListing('citizenships');
$year_2012= 'category:'.'"'.$years[2].'"';
in Blade file:
var datasetChart = <?php echo preg_replace('/"([a-zA-Z]+[a-zA-Z0-9_]*)":/','$1:', $citizenship_2012); ?>;
Expected output:
{
provinces: "Ontario",
category: "year2017",
measure: 19441.5648
}
The problem is that year2017
given in category
is also a column/attribute but I want to display it as above.