I have two arrays which I have passed to my Laravel view. I want to run a loop that will set a State variable equal to the total variable. For some reason the variables are not being set, even though I have defined them before the loop. I know I have the right variables lined up, because when I do a simple echo of the two I get the right results.
Complete code posted:
map.blade.php
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/screen.css">
<link rel="stylesheet" href="css/stately.css">
@define $AK = ""
@define $AL = ""
@define $AR = ""
@define $AZ = ""
@define $CA = ""
....
@define $WY = ""
@define $arr = array_combine($allstates, $alltotals)
@foreach ($arr as $allstates => $alltotals)
@define $array[$allstates] = $alltotals
{{ $allstates }} {{ $alltotals }}<br>
@define $allstates = $alltotals
{{ $allstates }} {{ $alltotals }}<br>
@endforeach
</head>
<body>
[Map here]
{{ $PA }}
</body>
Controller:
public function map()
{
$allstates = DB::table('distributors')->lists('state');
$alltotals = DB::table('distributors')->lists('total');
$merged = DB::table('distributors')->lists('state','total');
return View::make('map')
->with(compact('allstates'))
->with(compact('alltotals'))
->with(compact('merged'));
}
The outputs of this you can see on hennessey.io/map