-2

I wanted a calendar in my website, so i use full calendar lib to create these calendar with event. This I just did, now i have a new problem and i cant resolve it. for exemple i want that when it is create an event, it be possible to repeat these event every day or weeks

My code is:

   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');
    }
}

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;
    }


}

My controller:

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'));
}

i dont know how can fix this because i just a start in laravel. I need help to resolve it

Nuno
  • 61
  • 1
  • 10
  • 1
    "how can fix this". Fix what? You've described your _requirement_, but you haven't described your _problem_. Does your code have a bug? Or just you can't make it do what you want? Either way describe what it _does_ do vs what you need it to do. Then we have a starting point. P.S. FullCalendar itself supports events repeating across days of the week, but nothing more complex than that. There are two basic ways round it - use your server to generate all the "repeats" as individual event objects using server-side logic, or do something like this: https://stackoverflow.com/a/29393128/5947043 – ADyson Jul 14 '17 at 13:32

1 Answers1

0

Perfect opportunity for a for() loop. Since we have 52 weeks in a year we can just use Carbon to keep adding a week to the inital date.

 $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,
    );
  }
Taylor Foster
  • 1,103
  • 1
  • 11
  • 24