RodrigoCS
RodrigoCS

Reputation: 79

Laravel 5.1 FullCalendar table

Im trying to implement FullCalendar to my Laravel Project using this package https://github.com/maddhatter/laravel-fullcalendar I already created my Model: EventModel.php

<?php

namespace App;
use Illuminate\Database\Eloquent\Model;
class EventModel extends Model implements \MaddHatter\LaravelFullcalendar\Event
{

    protected $dates = ['start', 'end'];

    /**
     * Get the event's id number
     *
     * @return int
     */
    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;
    }
}

and my controller:

public function calendario() {
   $events = [];

    $events[] = \Calendar::event(
        'Event One', //event title
        false, //full day event?
        '2015-02-11T0800', //start time (you can also use Carbon instead of DateTime)
        '2015-02-12T0800', //end time (you can also use Carbon instead of DateTime)
        0 //optionally, you can specify an event ID
    );

    $events[] = \Calendar::event(
        "Valentine's Day", //event title
        true, //full day event?
        new \DateTime('2015-02-14'), //start time (you can also use Carbon instead of DateTime)
        new \DateTime('2015-02-14'), //end time (you can also use Carbon instead of DateTime)
        'stringEventId' //optionally, you can specify an event ID
    );

    $eloquentEvent = EventModel::first(); //EventModel implements MaddHatter\LaravelFullcalendar\Event

    $calendar = \Calendar::addEvents($events) //add an array with addEvents
        ->addEvent($eloquentEvent, [ //set custom color fo this event
            'color' => '#800',
        ])->setOptions([ //set fullcalendar options
            'firstDay' => 1
        ])->setCallbacks([ //set fullcalendar callback options (will not be JSON encoded)
            'viewRender' => 'function() {alert("Callbacks!");}'
        ]); 

    return view('hello', compact('calendar'));
}

But im getting this error when I go to my route:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'petdate.event_models' doesn't exist (SQL: select * from event_models limit 1)

Do I have to add a table?

Upvotes: 1

Views: 1041

Answers (1)

Valeria
Valeria

Reputation: 160

Follow your heart, no i'm kidding follow your model function:

protected $dates = ['start', 'end'];



 /**
     * Get the event's id number
     *
     * @return int
     */
    public function getId() {
        return $this->id;
    }

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

There you can see you need an id and a title, one is int and the other one is string. :)

Upvotes: 1

Related Questions