Mad hatter全日历颜色活动Laravel 5.4

时间:2017-03-10 14:29:10

标签: php laravel

当我设置“Wydzial 1”等标题时,我遇到了更改事件颜色的问题。 我知道我必须从db获取标题下次使用if if check check title但是接下来我不知道该怎么做。 我必须做类似的事情:我创建标题为“Wydzial 1”的事件,并使用颜色获取事件:红色,接下来我想要使用蓝色标题“Wydzial 2”制作事件。这样的事情。  现在它的工作所有添加事件与时间和其他但我不知道如何为事件做出不同的颜色。

控制器:

/**
 * Show the application dashboard.
 * 
 * @return \Illuminate\Http\Response
 */
public function index()
{
    $event = HomeModel::all();


    if($event->count()>0)
    {
        foreach ($event as $eve) 
        {
              $all_day = $eve->day;
              $events[] = \Calendar::event(
              $eve->title,
              $eve->all_day,
              $eve->start,
              $eve->end,
              $eve->id

              );
        }
    }
    else
    {
        $events = [];

    }

    $titles = HomeModel::where('title')->get();

    if($titles == "Wydzial 1") {
        $color = '#378006'; 
    } elseif ($titles == "Wydzial 2") {
        $color = '#ff0000';
    } elseif ($titles == "Wydzial 3") {
        $color = '#73e600';
    } else  {
        $color = '#0066ff';
    }

    $calendar = \Calendar::addEvents($events)
        ->setOptions([
            'FirstDay' => 1,
            'contentheight' => 650,
            'editable' => false,
            'allDay' => false,
            'aspectRatio' => 2,
            'slotLabelFormat' => 'HH:mm:ss',
            'timeFormat' => 'HH:mm',
            'color' => $color,           
            ])->setCallbacks([]);

    return view('home', compact('calendar'));

}

1 个答案:

答案 0 :(得分:0)

似乎你也可以将颜色作为选项传递(docs)?伪代码:

$dbEvents = HomeModel::all();

foreach($dbEvents as $dbEvent) {
    if($dbEvent->title == "Wydzial 1") {
        $color = '#378006'; 
    } elseif ($dbEvent->title == "Wydzial 2") {
        $color = '#ff0000';
    } elseif ($dbEvent->title == "Wydzial 3") {
        $color = '#73e600';
    } else  {
        $color = '#0066ff';
    }

    $events[] = \Calendar::event()->setOptions([
        'title' => $dbEvent->title,
        'color' => $color,
    ]);
}

$calendar = \Calendar::addEvents($events)->setOptions([
        'FirstDay' => 1,
        'contentheight' => 650,
        'editable' => false,
        'allDay' => false,
        'aspectRatio' => 2,
        'slotLabelFormat' => 'HH:mm:ss',
        'timeFormat' => 'HH:mm'
])->setCallbacks([]);