GoodAfternoon Stack,
Im trying to reach this goal: Pass events table to view and math them with corresponding div of same date. The problem I'm having is:
Class 'CalendarEvents' not found
I passed all the calenderEvents to the view. How do I use that in the @if statement below? I create the date variable in the for loop in the view. First, I tried pushing this into the array in the controller, but I kept receiving an exceed memory error. Is there a better method than what I have? Im trying to learn to do things the right way. Thanks!
Here is what I have:
HTML:
<div class = "box-content">
@foreach($years as $key1 => $year)
<h1>{{$key1}}</h1>
@foreach($year['months'] as $key2 => $month)
<p>{{$month['label']}}</p>
@for($i=1; $i<$month['day_count']+1; $i++ )
<?php $date = $key1.'-'.$key2.'-'.$i ?>
<p>{{$i}}</p>
@if(CalendarEvents::whereDate($date)->count() > 0) ----->//Error line here//
<p>{{$date}}</p>
@endif
@endfor
@endforeach
@endforeach
</div>
In my controller I have:
$year = date("Y",time());
$month = date("m",time());
$dayLabels = ['01' => 'January' , '02' => "Feburary", '03' => "March", '04' => "April", '05' => "May", '06' => "June", '07' => "July", '08' => "August", '09' => "September", "10" => "October", '11' => "November", '12' =>"December"];
$year_count = [$year];
$years=[];
for($i=0; $i<3; $i++){
array_push($year_count, ++$year);
}
foreach($year_count as $year){
$years[$year]= array();
foreach($dayLabels as $key => $label){
$firstDayOfTheWeek = date('N',strtotime($year.'-'.$key.'-01'));
$month_label = date('F', strtotime("2000-$key-01"));
$day_count = $this->_daysInMonth($key,$year);
$dayLabels[$key] = ['label' => $month_label, 'first_day' => $firstDayOfTheWeek, 'day_count' => $day_count];
}
$years[$year]=['months'=>$dayLabels];
}
$events = CalenderEvents::all();
return view('user', compact('years', 'events'));