Monday, March 13, 2017

Mad hatter full calendar color events Laravel 5.4

Hi i got some problem with change event color when I set title like 'Wydzial 1' etc. I know I must fetch title from db next use if to check title but next I don't know what to do. I must do something like that: I create event with title 'Wydzial 1' and get event with color:red, Next i want make event with title 'Wydzial 2' with blue color. Something like that. Now its working all adding event with time and other but I dont know how make different color for event.

Controller:

/**
 * 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'));

}



via Mariusz

Advertisement