У меня есть коллекция, которая содержит календарь событий на год. Например, отпуск, отпуск по болезни и т. Д. c.
Я пытаюсь создать календарь для их отображения, но он работает очень медленно, поэтому я думаю, что, должно быть, плохо.
Я читаю каждый день года по Carbon dayOfYear, и у меня есть следующий геттер, который я вызываю, чтобы вытащить события на этот день:
public function getDayOfYearAttribute()
{
$starter = Carbon::parse($this->date);
return $starter->dayOfYear;
}
Я звоню с:
$today = $caldays->where('day_of_year', $dayofyear);
и затем l oop через любые отображаемые события.
Что может быть лучше для этого?
Спасибо.
это мой контроллер :
public function fullcalendar()
{
$ret = \App\CalDay::all();
$ret = $ret->sortBy('day_of_year');
//++ default to this year
$year = Carbon::now()->format('Y');
return View::make('holidaycal.home')
->with('year', $year)
->with('caldays', $ret);
}
это мой код с l oop. это еще не блейд, но так немного беспорядок, просто тестирую logi c.
$starter = Carbon::parse($year.'-01-01 00:00:00.000000');
echo '<table width="6325px" class="table table-striped table-bordered">';
$dayofyear=1;
for ($x = 1;$x < 13; $x++) {
$starter->month = $x;
echo '<tr>';
echo '<td width="125px">';
echo '</td>';
for ($y = 1;$y < $starter->daysInMonth + 1; $y++) {
echo '<td width="200px">';
$starter->day = $y;
echo $starter->isoFormat('ddd Do MMM');
echo '</td>';
}
$starter->day = 1;
echo '</tr>';
echo '<tr>';
echo '<td>';
echo $starter->englishMonth;
echo '</td>';
for ($i = 0; $i < $starter->daysInMonth; $i++) {
$today = $caldays->where('day_of_year', $dayofyear);
echo '<td class="text-tiny">';
foreach ($today as $event) {
echo '<div>';
echo $event->user->name .'('. $event->value .')<br/>';
echo '</div>';
}
echo '</td>';
$dayofyear++;
}
echo '</tr>';
}
echo '</table>';
перенос таблицы:
public function up()
{
Schema::create('cal_days', function (Blueprint $table) {
$table->increments('id');
$table->bigInteger('user_id')->unsigned()->nullable()->index();
$table->dateTime('date');
//+ days or hours
$table->string('type','1')->default("D"); //D=days,H=hours
$table->decimal('value',5,2)->unsigned()->index();
$table->bigInteger('added_by_id')->unsigned()->nullable()->index();
$table->integer('time_type_id')->unsigned()->index();
$table->string('description',100)->nullable();
$table->timestamps();
});
}