2017-03-10 59 views
0

嗨我遇到一些問題,改變事件的顏色,當我設置像'Wydzial 1'等標題 我知道我必須從數據庫獲取標題下次使用如果檢查標題,但接下來我不'不知道該怎麼做。 我必須做這樣的事情:我創建了標題爲'Wydzial 1'的活動,並獲得帶有顏色的事件:紅色,接下來我想用藍色標題'Wydzial 2'進行活動。類似的東西。 現在它的所有工作都與時間和其他事件相關,但我不知道如何爲事件製作不同的顏色。瘋狂的帽子完整的日曆顏色事件Laravel 5.4

控制器:

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

} 

回答

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([]); 
+0

,如果我喜歡你使寫入其犯規展示活動;/ – Mariusz

+0

我已經更新的例子,以反映您的編輯的變化... – Wietse