2017-07-14 110 views
-2

我想在我的網站的日曆,所以我使用完整的日曆lib來創建這些日曆與事件。這我剛剛做了,現在我有一個新的問題,我無法解決它。對於爲例我想,當它創建一個事件,它可以每天或幾周重複這些事件laravel完整的日曆重複事件

我的代碼是:

class CreateEventModelTable extends Migration 
{ 
    public function up() 
    { 
     Schema::create('event_model', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->string('title'); 
      $table->boolean('all_day'); 
      $table->datetime('start'); 
      $table->datetime('end'); 
      $table->timestamps(); 
     }); 
    } 
    public function down() 
    { 
     Schema::dropIfExists('event_model'); 
    } 
} 

型號:

class EventModel extends Model implements \MaddHatter\LaravelFullcalendar\Event 
{ 
    // 
    protected $dates = ['start', 'end']; 
    protected $table = 'event_model'; 


    public function getId() { 
     return $this->id; 
    } 

    /** 
    * Get the event's title 
    * 
    * @return string 
    */ 
    public function getTitle() 
    { 
     return $this->title; 
    } 

    /** 
    * Is it an all day event? 
    * 
    * @return bool 
    */ 
    public function isAllDay() 
    { 
     return (bool)$this->all_day; 
    } 

    /** 
    * Get the start time 
    * 
    * @return DateTime 
    */ 
    public function getStart() 
    { 
     return $this->start; 
    } 

    /** 
    * Get the end time 
    * 
    * @return DateTime 
    */ 
    public function getEnd() 
    { 
     return $this->end; 
    } 

    public function getRow(){ 
     return $this->row; 
    } 


} 

我的控制器:

public function create() { 
    $events = []; 
    $events[] = \Calendar::event(
    'Teste', 
    false, 
    '2017-07-10', 
    '2017-07-10', 
    '[ 1, 4 ]' 
    ); 
    $events[] = \Calendar::event(
    'Teste2', //event title 
    true, //full day event? 
    new DateTime('2017-07-14'), //start time (you can also use Carbon instead of DateTime) 
    new DateTime('2015-07-14') //end time (you can also use Carbon instead of DateTime) 
); 

    $eloquentEvent = EventModel::first(); 
    $calendar = \Calendar::addEvents($events) 
    ->addEvent($eloquentEvent, ['color' => '#800', 
    ])->setOptions([ 
     'firstDay' => 1 
    ])->setCallbacks(['viewRender' => 'function() {alert("Callbacks");}' 
    ]); 
    return view('CFAE.calendar', compact('calendar')); 
} 

我不知道如何解決這個問題,因爲我只是一個開始在laravel。我需要幫助來解決它

+1

「如何解決這個問題」。修復什麼?你描述了你的_requirement_,但是你沒有描述你的_problem_。你的代碼是否有bug?或者只是你不能讓它做你想做的事?無論哪種方式描述它做什麼,而不是你需要做什麼。那麼我們有一個起點。附: FullCalendar本身支持一週中幾天重複的事件,但沒有比這更復雜的事情。有兩種基本方法 - 使用服務器使用服務器端邏輯將所有「重複」作爲單個事件對象生成,或者執行如下操作:https://stackoverflow.com/a/29393128/5947043 – ADyson

回答

0

完美的機會爲for()循環。由於我們每年有52周,因此我們可以使用Carbon繼續爲初始日期增加一週。

$events = []; 

$start_date = Carbon::parse('{some_date_here}'); 

for($i = 0; $i <= 52; $i++){ 
    $start_date = $start_date->addWeek(); 
    $events[] = \Calendar::event(
    'Event Name', //event title 
     true, //full day event? 
     $start_date, 
     $start_date, 
    ); 
    }