PHP code example of dhonions / laravel-calendar

1. Go to this page and download the library: Download dhonions/laravel-calendar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dhonions / laravel-calendar example snippets


$event = \Calendar::event(
    "Valentine's Day", //event title
    true, //full day event?
    '2015-02-14', //start time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg)
    '2015-02-14', //end time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg),
    1, //optional event ID
    [
        'url' => 'http://full-calendar.io'
    ]
);

class EventModel extends Eloquent implements \Dhonions\LaravelCalendar\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;
    }
}

class EventModel extends Eloquent implements \Dhonions\LaravelCalendar\IdentifiableEvent
{

    // Implement all Event methods ...

    /**
     * Get the event's ID
     *
     * @return int|string|null
     */
    public function getId();

}


$event = \Calendar::event(
    "Valentine's Day", //event title
    true, //full day event?
    '2015-02-14', //start time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg)
    '2015-02-14', //end time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg),
    1, //optional event ID
    [
        'url' => 'http://full-calendar.io',
        //any other full-calendar supported parameters
    ]
);



class CalendarEvent extends \Illuminate\Database\Eloquent\Model implements \Dhonions\LaravelCalendar\Event
{
    //...

    /**
     * Optional FullCalendar.io settings for this event
     *
     * @return array
     */
    public function getEventOptions()
    {
        return [
            'color' => $this->background_color,
			//etc
        ];
    }

    //...
}


$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
);

$calendar = new Calendar();
$calendar->addEvents($events);
$calendar->setOptions([
    'locales' => 'allLocales',
    'locale' => 'fr',
    'firstDay' => 0,
    'displayEventTime' => true,
    'selectable' => true,
    'initialView' => 'timeGridWeek',
    'headerToolbar' => [
        'left' => 'prev,next today myCustomButton',
        'center' => 'title',
        'right' => 'dayGridMonth,timeGridWeek,timeGridDay'
    ],
    'customButtons' => [
        'myCustomButton' => [
            'text'=> 'custom!',
            'click' => 'function() {
                alert(\'clicked the custom button!\');
            }'
        ]
    ]
]);
$calendar->setId('1');
$calendar->setCallbacks([
    'select' => 'function(selectionInfo){}',
    'eventClick' => 'function(event){}'
]);

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

$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
);

$calendar = new Calendar();
$calendar->addEvents($events)
->setOptions([
    'plugins' => [ 'window.interaction', 'window.momentPlugin', 'window.dayGridPlugin', 'window.timeGridPlugin', 'window.listPlugin' ],
    'locales' => 'window.allLocales',
    'locale' => 'fr',
    'firstDay' => 0,
    'displayEventTime' => true,
    'selectable' => true,
    'initialView' => 'timeGridWeek',
    'headerToolbar' => [
        'left' => 'prev,next today myCustomButton',
        'center' => 'title',
        'right' => 'dayGridMonth,timeGridWeek,timeGridDay'
    ],
    'customButtons' => [
        'myCustomButton' => [
            'text'=> 'custom!',
            'click' => 'function() {
                alert(\'clicked the custom button!\');
            }'
        ]
    ]
]);
$calendar->setId('1');
$calendar->setEs6();
$calendar->setCallbacks([
    'select' => 'function(info) {
        alert(\'selected \' + info.startStr + \' to \' + info.endStr);
    }',
    'eventClick' => 'function(info) {
        alert(\'Event: \' + info.event.title);
        alert(\'Coordinates: \' + info.jsEvent.pageX + \',\' + info.jsEvent.pageY);
        alert(\'View: \' + info.view.type);
        
        // change the border color just for fun
        info.el.style.borderColor = \'red\';
    }',
    'dateClick' => 'function(info) {
        alert(\'clicked \' + info.dateStr);
    }'
]);

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

// FullCalendar.io
import { Calendar } from '@fullcalendar/core';
window.Calendar = Calendar;

import interaction from '@fullcalendar/interaction';
window.interaction = interaction;

import dayGridPlugin from '@fullcalendar/daygrid';
window.dayGridPlugin = dayGridPlugin;

import timeGridPlugin from '@fullcalendar/timegrid';
window.timeGridPlugin = timeGridPlugin;

import listPlugin from '@fullcalendar/list';
window.listPlugin = listPlugin;

import momentPlugin from '@fullcalendar/moment';
window.momentPlugin = momentPlugin;

import allLocales from '@fullcalendar/core/locales-all';
window.allLocales = allLocales;

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="{{ mix('/css/app.css') }}" rel="stylesheet">
    
    <script src="{{ mix('/js/app.js') }}"></script>
</head>
<body>
    {!! $calendar->calendar() !!}
    {!! $calendar->script() !!}
</body>
</html>