Laravel FullCalendar.io Helper

Overview

Laravel 5 Full Calendar Helper

Latest Stable Version Total Downloads Latest Unstable Version License

For Laravel 4.2: use the laravel-4 branch

This is a simple helper package to make generating http://fullcalendar.io in Laravel apps easier.

Installing

Require the package with composer using the following command:

composer require maddhatter/laravel-fullcalendar

Or add the following to your composer.json's require section and composer update

"require": {
	"maddhatter/laravel-fullcalendar": "~1.0"
}

Laravel 5.4 (and earlier)

Register the service provider in your app.php config file:

MaddHatter\LaravelFullcalendar\ServiceProvider::class,

And optionally create an alias:

'Calendar' => MaddHatter\LaravelFullcalendar\Facades\Calendar::class,

Laravel 5.5+

The provider and Calendar alias will be registered automatically.

You will also need to include fullcalendar.io's files in your HTML.

Usage

Creating Events

Using event():

The simpliest way to create an event is to pass the event information to Calendar::event():

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

Implementing Event Interface

Alternatively, you can use an existing class and have it implement MaddHatter\LaravelFullcalendar\Event. An example of an Eloquent model that implements the Event interface:

class EventModel extends Eloquent 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;
    }
}

IdentifiableEvent Interface

If you wish for your existing class to have event IDs, implement \MaddHatter\LaravelFullcalendar\IdentifiableEvent instead. This interface extends \MaddHatter\LaravelFullcalendar\Event to add a getId() method:

class EventModel extends Eloquent implements \MaddHatter\LaravelFullcalendar\IdentifiableEvent
{

	// Implement all Event methods ...

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

}

Additional Event Parameters

If you want to add additional parameters to your events, there are two options:

Using Calendar::event()

Pass an array of 'parameter' => 'value' pairs as the 6th parameter to Calendar::event():

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

Add an getEventOptions method to your event class

<?php
class CalendarEvent extends \Illuminate\Database\Eloquent\Model implements \MaddHatter\LaravelFullcalendar\Event
{
	//...

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

	//...
}

Create a Calendar

To create a calendar, in your route or controller, create your event(s), then pass them to Calendar::addEvent() or Calendar::addEvents() (to add an array of events). addEvent() and addEvents() can be used fluently (chained together). Their second parameter accepts an array of valid FullCalendar Event Object parameters.

Sample Controller code:

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

Sample View

Then to display, add the following code to your View:

<!doctype html>
<html lang="en">
<head>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/>


    <style>
        /* ... */
    </style>
</head>
<body>
    {!! $calendar->calendar() !!}
    {!! $calendar->script() !!}
</body>
</html>

Note: The output from calendar() and script() must be non-escaped, so use {!! and !!} (or whatever you've configured your Blade compiler's raw tag directives as).

The script() can be placed anywhere after calendar(), and must be after fullcalendar was included.

This will generate (in February 2015):

Comments
  • Not working in laravel 6

    Not working in laravel 6

    i used this package in one of my big systems that was built with laravel 5.6 and now i upgraded the systems to laravel 6 and now i am not able to install this package in laravel 6.

    opened by devlimon 12
  • Multiple Calendars on One Page

    Multiple Calendars on One Page

    Displaying one calendar works fine but when attempting to show two separate calendars it only displays once. Taking a look at the generated code, it seems that it is naming both calendars the same name - whether I let the package automatically choose the name or even setting the id via setId()...it still chooses the same name for both.

    Is there a workaround to this?

    opened by bfblackjack 10
  • Can't seem to display the calendar

    Can't seem to display the calendar

    I'm quite new to Laravel so I might be doing this all wrong, but I can't seem to get the calendar displayed. I keep getting the error 'Undefined variable: calendar (View: /home/vagrant/Code/Laravel/resources/views/pages/calendar.blade.php)'

    I made a stackoverflow question with all the code here: http://stackoverflow.com/questions/30662238/cannot-get-fullcalendar-to-work-laravel-5

    Mind helping me out? Thanks, Cedric

    opened by CedricBongaerts 10
  • Argument 1 passed to MaddHatter\LaravelFullcalendar\Calendar::addEvent()

    Argument 1 passed to MaddHatter\LaravelFullcalendar\Calendar::addEvent()

    I am getting this error

    ErrorException in Calendar.php line 142: Argument 1 passed to MaddHatter\LaravelFullcalendar\Calendar::addEvent() must implement interface MaddHatter\LaravelFullcalendar\Event, null given, called in C:\wamp\www\musicCentral\app\Http\Controllers\AgendaController.php on line 69 and defined

    I have used the example code How can I fix this?

    opened by koffielyder 9
  • Change Lang

    Change Lang

    i need change the language of te calendar to 'es' by default, i pasted this in Calendar.php and didn't work

    protected $defaultOptions = [ 'header' => [ 'left' => 'prev,next today', 'center' => 'title', 'right' => 'month,agendaWeek,agendaDay', ], 'eventLimit' => true, 'lang' => 'es' ];

    opened by Luismij 8
  • Allow user to set event source as URL

    Allow user to set event source as URL

    Check for existing events parameter key in getOptionsJson prior to loading events queue. This allows the user to set the events key in the options and set a feed url or function as the source.

    It seems that getOptionsJson assumed that all events were to be added to the calendar on the Laravel side, and any attempt to set the events option setting was being clobbered. Added a quick isset() test for the events option prior to loading it up from the eventCollection, and if it exists, leave it alone.

    opened by zenphp 6
  • calendar not displaying despite calendar object successfully passed to view

    calendar not displaying despite calendar object successfully passed to view

    My blade template generates the following HTML below but im just getting the navbar and the card with its header.

    if I DD the calendar object, all the events are in there.

    HELP!

    Apologies in advance if im being dumb

    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    
        <!-- CSRF Token -->
        <meta name="csrf-token" content="UO0pN2Gyaiva6fbH6NOcpAZlLUcqcXQMKXKuOYkB">
    
        <title>Laravel</title>
    
        <!-- Scripts -->
        <script src="http://127.0.0.1:8000/js/app.js" defer></script>
    
        <!-- Fonts -->
        <link rel="dns-prefetch" href="https://fonts.gstatic.com">
        <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
    
        <!-- Styles -->
        <link href="http://127.0.0.1:8000/css/app.css" rel="stylesheet">
    
        <!-- Calendar -->
        <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
        <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/>
        
    
    </head>
    <body>
        <div id="app">
            <nav class="navbar navbar-expand-md navbar-light navbar-laravel">
                <div class="container">
                    <a class="navbar-brand" href="http://127.0.0.1:8000">
                        Laravel
                    </a>
                    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>
    
                    <div class="collapse navbar-collapse" id="navbarSupportedContent">
                        <!-- Left Side Of Navbar -->
                        <ul class="navbar-nav mr-auto">
    
                        </ul>
    
                        <!-- Right Side Of Navbar -->
                        <ul class="navbar-nav ml-auto">
                            <!-- Authentication Links -->
                                                        <li class="nav-item dropdown">
                                    <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                                        David Griffiths <span class="caret"></span>
                                    </a>
    
                                    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                        <a class="dropdown-item" href="http://127.0.0.1:8000/logout"
                                           onclick="event.preventDefault();
                                                         document.getElementById('logout-form').submit();">
                                            Logout
                                        </a>
    
                                        <form id="logout-form" action="http://127.0.0.1:8000/logout" method="POST" style="display: none;">
                                            <input type="hidden" name="_token" value="UO0pN2Gyaiva6fbH6NOcpAZlLUcqcXQMKXKuOYkB">                                    </form>
                                    </div>
                                </li>
                                                </ul>
                    </div>
                </div>
            </nav>
    
            <main class="py-4">
                <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">Calendar</div>
    
                    <div class="card-body calendar">
                        
    
                        <div id="calendar-hcfyHurv"></div>
                        <script>
        $(document).ready(function(){
            $('#calendar-hcfyHurv').fullCalendar({"header":{"left":"prev,next today","center":"title","right":"month,agendaWeek,agendaDay"},"eventLimit":true,"events":[{"id":null,"title":"job1","allDay":true,"start":"2017-09-11T00:00:00+00:00","end":"2017-09-13T00:00:00+00:00","color":"#f05050","url":"pass here url and any route"},{"id":null,"title":"job2","allDay":true,"start":"2017-09-13T00:00:00+00:00","end":"2017-09-15T00:00:00+00:00","color":"#f05050","url":"pass here url and any route"},{"id":null,"title":"job3","allDay":true,"start":"2018-01-01T00:00:00+00:00","end":"2018-01-03T00:00:00+00:00","color":"#f05050","url":"pass here url and any route"}]});
        });
    </script>
    
    
    
                    </div>
                </div>
            </div>
        </div>
    </div>
            </main>
        </div>
    </body>
    </html>
    
    opened by davidjtgriffiths 5
  • Failed to be installed on Laravel 6.2

    Failed to be installed on Laravel 6.2

    I have been trying on installing this package for my new project using the command: composer require maddhatter/laravel-fullcalendar but I am getting this error: Your requirements could not be resolved to an installable set of packages.

    Any ideas to resolve the issue would be appreciated.

    opened by kalideir 4
  • Laravel 5.7 using Bootstrap 4 - Header navigation buttons not appearing

    Laravel 5.7 using Bootstrap 4 - Header navigation buttons not appearing

    I have successfully used this package in the past with a laravel 5.5 on a Bootstrap 3 theme.

    I have the calendar rendering but all I see on the header is the Month and Year, missing is the left hand navigation arrow buttons and the right hand change view buttons. The fullcalendar.io library version I installed in V3.9.0.

    Is there a step that I have missed to turn on the view options?

    opened by Dmarthaller 4
  • Using Laravel 4.2 : can I pass the url and the event color whiten $events array

    Using Laravel 4.2 : can I pass the url and the event color whiten $events array

    Hi I tried to get all the events from my database using foreach

    the Evant implement MaddHatter\LaravelFullcalendar\Event

    $eloquentEvent = Evant::all(); //EventModel implements MaddHatter\LaravelFullcalendar\Event
            
            $events = [];
            foreach ($eloquentEvent as $ge) {
                $events[] = Calendar::event(
                    $ge->title, //event title
                    false, //full day event?
                    $ge->start_time, //start time (you can also use Carbon instead of DateTime)
                    $ge->end_time //end time (you can also use Carbon instead of DateTime)
                );
            }
    
            $calendar = Calendar::addEvents($events);
    
            return View::make('admin.event.view', compact('calendar'));
    

    it's working OK, but can't find a way to pass the url and color for each event. or can you please suggest me a better way to do this

    opened by johnef 4
  • Issue after fresh install

    Issue after fresh install

    Hey,

    just did a fresh composer install of laravel-fullcalendar and followed instructions for installation.

    Then i copied the sample code for the view and controller and I am getting the following error

    Fatal error: Class 'App\Http\Controllers\EventModel' not found

    I tried adding use at the top to ensure it was looking for the right class

    use MaddHatter\LaravelFullcalendar\Calendar;

    we also have a header.php that gets included and I placed the links to the fullcalendar files in there so they are included.

    any thoughts on what I have done wrong ?

    Thanks

    opened by Movian 4
  • Laravel 9.x Compatibility

    Laravel 9.x Compatibility

    This is an automated pull request from Shift to update your package code and dependencies to be compatible with Laravel 9.x.

    Before merging, you need to:

    • Checkout the l9-compatibility branch
    • Review all comments for additional changes
    • Thoroughly test your package

    If you do find an issue, please report it by commenting on this PR to help improve future automation.

    opened by laravel-shift 1
  • Ekstra Field Description

    Ekstra Field Description

    Hello how to ı added ekstra field in boostrap poppover ?

    ` $events = []; $data = Takvim::all();

        if($data->count())
        {
            foreach ($data as $key => $value)
            {
                $events[] = Calendar::event(
                    $value->title,
                    true,
                    new \DateTime($value->start_date),
                    new \DateTime($value->end_date.'+1 day'),
                    null,
                    // Add color
                    [
                        'color' => '#000000',
                        'textColor' => '#ffffff',
                        'locale'=>'tr',
                    ]
                );
    
    
            }
        }
        $calendar = \Calendar::addEvents($events)
            ->setOptions([
    
            ])
            ->setCallbacks([
                'eventRender'=>'function (event, element) {
            element.attr(\'data-toggle\', "tooltip");
            element.attr(\'data-placement\', "top");
            element.attr(\'description\', event.description);}',
            ]);
    

    `

    http://prntscr.com/s9px2f not working.

    opened by einste12 0
Releases(v1.3.0)
Owner
Shawn Tunney
Shawn Tunney
Cache-purge-helper - Additional instances where nginx-helper and lscache plugin should be purged.

cache-purge-helper Additional instances where nginx-helper and lscache plugin should be purged. Install Extract the zip file. Upload them to /wp-conte

Jordan 10 Oct 5, 2022
Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries, this package will contain all advanced SQL

Syrian Open Source 15 Nov 20, 2022
The missing laravel helper that allows you to inspect your eloquent queries with it's bind parameters

Laravel Query Inspector The missing laravel helper that allows you to ispect your eloquent queries with it's bind parameters Motivations Let's say you

Mouad ZIANI 59 Sep 25, 2022
Laravel-Mix helper for projects with complex & multi assets.

Laravel-Mix helper for projects with complex & multi assets. ?? Getting started Since mix introduced in laravel 5.4 it is recommended to use this pack

Fandogh 27 Oct 4, 2022
A Laravel response helper methods.

A Laravel response helper methods. The package respond provides a fluent syntax to form array or json responses.

Najm Njeim 5 Nov 2, 2021
`dd` is a helper method in Laravel. This package will add the `dd` to your application.

dd dd is a helper method in Laravel. This package will add the dd to your application. Install Run composer require larapack/dd 1.* For Laravel Larave

Larapack 109 Dec 26, 2022
An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality.

Support An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality. Ins

Ian Olson 3 Apr 14, 2021
Active State Helper for Laravel Blade

laravel-activehelper Active State Helper for Laravel Blade Lightweight and simple Introduction Basically we do like this. <li class="sidebar {{ Reques

Ahmad Irsyadul Ibad 4 Sep 25, 2022
Laravel helper to generate the QRcode for ZATCA E-Invoicing system

Laravel-ZATCA Unofficial package to implement ZATCA QRcode for E-Invoicing. Requirements PHP >= 7.4 An mbstring extension Dependencies chillerlan/php-

Moh. Php Master .. 3 Aug 16, 2022
Laravel IDE Helper

Laravel IDE Helper Generator Complete PHPDocs, directly from the source This package generates helper files that enable your IDE to provide accurate a

Barry vd. Heuvel 12.8k Dec 28, 2022
Helper class for working with Laravel Mix in WordPress themes and plugins.

Hybrid\Mix Hybrid Mix is a class for working with Lavarel Mix. It adds helper methods for quickly grabbing asset files cached in the mix-manifest.json

Theme Hybrid 9 Jun 2, 2022
Laravel Stats Helper

Laravel Stats Helper With laravel-stats-helper you can get the statistics of two values or an array of values. It allows you to get the difference, pe

Label84 24 Jan 25, 2022
A convenient helper for using the laravel-seo package with Filament Admin and Forms

Combine the power of Laravel SEO and Filament PHP. This package is a convenient helper for using the laravel-seo package with Filament Admin and Forms

Ralph J. Smit 39 Dec 21, 2022
Localization Helper - Package for convenient work with Laravel's localization features and fast language files generation

Localization Helper Package for convenient work with Laravel's localization features and fast language files generation. Installation Via Composer $ c

Galymzhan Begimov 0 Jul 13, 2019
:passport_control: Helper for Google's new noCAPTCHA (reCAPTCHA v2 & v3)

noCAPTCHA (new reCAPTCHA) By ARCANEDEV© What is reCAPTCHA? reCAPTCHA is a free service that protects your site from spam and abuse. It uses advanced r

ARCANEDEV 341 Nov 19, 2022
A collection of helper functions that I use across my projects.

A collection of helper functions that I use across my projects. This package includes some of the helper functions that I tend to use in all of my pro

Ryan Chandler 33 Oct 18, 2022
SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization).

SEO Helper By ARCANEDEV© SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization). Feel free to check out the rele

ARCANEDEV 301 Nov 25, 2022
Live Helper Chat - live support for your website. Featuring web and mobile apps, Voice & Video & ScreenShare. Supports Telegram, Twilio (whatsapp), Facebook messenger including building a bot.

Live helper chat It's an open-source powered application, which brings simplicity and usability in one place. With live helper chat you can bring live

Live Helper Chat 1.7k Dec 29, 2022
This package provides new helper functions that take care of handling all the translation hassle and do it for you.

Laravel Translate Message ?? This package provides new helper functions that take care of handling all the translation hassle and do it for you. Insta

Basel Rabia 17 Feb 8, 2022