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 dont know what to do. I must do somethink 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. Somethink like that. Now its working all adding event with time and other but i dont know how make diffrents 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