In a blade template, I have:
@foreach($users as $user)
{{ $user->id }} // this displays just fine, the number 1
{{ $weeklyCallsArray{$user->id} }} // get "Undefined offset:" error
{{ $weeklyCallsArray{1} }} // this works fine
@endforeach
How can I get the array to display with the corresponding user? I want to use something like:
$weeklyCallsArray{user->id}
Here is my query and return in the controller:
$users = DB::table('users')->get();
foreach ($users as $user) {
$userId = $user->id;
$countThisWeek = DB::table('calls')
->where('called_by', '=', $userId)
->where('calledd_on', '>=', Carbon::now()->startOfWeek())
->count();
$weeklyCallArray[$userId] = $countThisWeek;
}
return view('users')
->with(['users' => $users])
->with(['weeklyCallsArray' => $weeklyCallsArray]);