laravel完整的日历重复事件
问题描述:
我想在我的网站的日历,所以我使用完整的日历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。我需要帮助来解决它
答
完美的机会为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,
);
}
“如何解决这个问题”。修复什么?你描述了你的_requirement_,但是你没有描述你的_problem_。你的代码是否有bug?或者只是你不能让它做你想做的事?无论哪种方式描述它做什么,而不是你需要做什么。那么我们有一个起点。附: FullCalendar本身支持一周中几天重复的事件,但没有比这更复杂的事情。有两种基本方法 - 使用服务器使用服务器端逻辑将所有“重复”作为单个事件对象生成,或者执行如下操作:https://*.com/a/29393128/5947043 – ADyson