Laravel 6 FullCalendar Tutorial

Admin   Laravel   161  2021-03-17 09:40:05

hii guys,

In this example,I will show to you, how you can integrate a fullcalendar in laravel 6 application. i write step by step instruction of laravel 6 FullCalendar ajax example.

you will learn step by step how you can simply use a fullcalendar with its events. In this example, We will implement add an event, update event and delete event on the fullcalendar using ajax.

Step 1: Install Laravel Project

First, you need to download the laravel fresh setup. Use this command then download laravel project setup :

 

composer create-project --prefer-dist laravel/laravel blog

Step 2: Setup Database

After successfully install laravel 6 Application, Go to your project .env file and set up database credential and move next step :

 

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=here your database name

DB_USERNAME=here database username

DB_PASSWORD=here database password

Step 3: Create Migration & Model

Now you will create a table name event and it’s migration name create automatically. use this command in your terminal :

 

php artisan make:model Event -m

It command will create one model name Event and also create one migration file for the Events table.

 

<?php

use Illuminate\Support\Facades\Schema;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Database\Migrations\Migration;

class CreateEventsTable extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

Schema::create('events', function (Blueprint $table) {

$table->increments('id');

$table->string('title');

$table->dateTime('start');

$table->dateTime('end');

$table->timestamps();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

Schema::dropIfExists('events');

}

}

Next,this command use to in your terminal then this setup create to in your database.

 

php artisan migrate

Make Route

you can create to route in web.php file.

 

//fullcalender

Route::get('/fullcalendareventmaster','[email protected]');

Route::post('/fullcalendareventmaster/create','[email protected]');

Route::post('/fullcalendareventmaster/update','[email protected]');

Route::post('/fullcalendareventmaster/delete','[email protected]');

Step:4 Create Controller

you need to create a controller name FullCalendarEventMasterController.this command use to your terminal.

 

php artisan make:controller FullCalendarEventMasterController

After create to methods:

The first method is index(), it will show you fullcalendar.

The second method is create(), it will store your events into the database.

The third method is update(), it will update your fullcalendar event into database.

The final method is destroy(), it will delete your events into the database and fullcalendar.

 

<?php

namespace App\Http\Controllers;

use App\Event;

use Illuminate\Http\Request;

use Redirect,Response;

class FullCalendarEventMasterController extends Controller

{

public function index()

{

if(request()->ajax())

{

$start = (!empty($_GET["start"])) ? ($_GET["start"]) : ('');

$end = (!empty($_GET["end"])) ? ($_GET["end"]) : ('');

$data = Event::whereDate('start', '>=', $start)->whereDate('end', '