In this tutorial you will learn about the Laravel 8 FullCalendar Vue JS Tutorial Example and its application with practical example.
In this Laravel 8 FullCalendar Vue JS Tutorial Example tutorial I’ll show you how to display events on the calendar using vue js fullcalendar components in laravel 8 apps. In this tutorial you will learn to display events on the calendar using vue js fullcalendar in laravel 8. This tutorial you will also learn to show dynamic event data on vue js calendar using Vue full calendar components in laravel vue js.
- Laravel 8 FullCalendar Vue JS Tutorial Example
- Step 1: Install Laravel 8 App
- Step 2: Connecting App to Database
- Step 3: Create Model And Migration
- Step 4: NPM Module Configuration For Vue Js
- Step 5: Add Routes
- Step 6: Create Controller By Command
- Step 7: Create Vue Component
- Step 8: Create Blade Views And Initialize Vue Components
- Step 9: Run Development Server
Laravel 8 FullCalendar Vue JS Tutorial Example
In this step by step tutorial I will demonstrate you how to display events on the calendar using vue js fullcalendar components in laravel 8 applications. Please follow the instruction given below:
- Step 1: Install Laravel 8 App
- Step 2: Connecting App to Database
- Step 3: Create Model And Migration
- Step 4: NPM Module Configuration For Vue Js
- Step 5: Add Routes
- Step 6: Create Controller By Command
- Step 7: Create Vue Component
- Step 8: Create Blade Views And Initialize Vue Components
- Step 9: Run Development Server
Step 1: Install Laravel 8 App
First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command
1 |
composer create-project --prefer-dist laravel/laravel blog |
Step 2: Connecting App to Database
Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.
1 2 3 4 5 6 |
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=here your database name here DB_USERNAME=here database username here DB_PASSWORD=here database password here |
Step 3: Create Model And Migration
Now, in this step we will create model and migration file. Please run the following command:
1 |
php artisan make:model Event -m |
The above command will create a model name Event.php and also create a migration file for the events table. Lets open create_events_table.php migration file from database>migrations and replace up() function with following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?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->bigIncrements('id'); $table->string('title'); $table->date('start'); $table->date('end'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('events'); } } |
Now, in this step we will create model and migration file. Please run the following command:
1 |
php artisan migrate |
Next, Navigate to app/Models/Event.php and update the following code into your Event.php model as follow:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Event extends Model { use HasFactory; protected $fillable = [ ]; } |
Step 4: NPM Module Configuration For Vue Js
1 |
php artisan preset vue |
Install all Vue dependencies:
1 |
npm install |
After that, install vue full calendar dependencies by using the below command:
1 2 3 4 5 6 7 8 9 10 |
npm install --save vue-full-calendar npm install --save babel-runtime npm install babel-preset-stage-2 --save-dev npm install moment --save |
Step 5: Add Routes
After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.
routes/web.php
1 2 3 |
use App\Http\Controllers\EventController; Route::get('events', [EventController::class, 'index']); |
Step 6: Create Controller By Command
Now, lets create a controller named EventController using command given below –
1 |
php artisan make:controller EventController |
Go to app\Http\Controllers
and open EventController.php file. Then put the following code into your EventController.php file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
namespace App\Http\Controllers; use App\Models\Event; use Illuminate\Http\Request; class EventController extends Controller { public function index(Request $request) { $events = Event::get(['title','start']); return response()->json(["events" => $events]); } } |
Step 7: Create Vue Component
In this step we will create a Vue component. Go to resources/assets/js/components
folder and create a file called FullCalendarComponent.vue. Now, put the following code into your FullCalendarComponent.vue components file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<template> <div class="container"> <full-calendar :event-sources="eventSources"></full-calendar> </div> </template> <script> export default{ data() { return { eventSources: [ { events(start, end, timezone, callback) { axios.get('http://localhost:8000/events').then(response => { callback(response.data.events) }) }, color: 'yellow', textColor: 'black', } ] } } } </script> |
Now open resources/assets/js/app.js
and include the FullCalendarComponent.vue component as follow:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
require('./bootstrap'); import 'fullcalendar/dist/fullcalendar.css'; window.Vue = require('vue'); import FullCalendar from 'vue-full-calendar'; //Import Full-calendar Vue.use(FullCalendar); Vue.component('fullcalendar-component', require('./components/FullCalendarComponent.vue').default); const app = new Vue({ el: '#app', }); |
Step 8: Create Blade Views And Initialize Vue Components
In this step we will create a blade view file. Go to resources/views and create one folder named layouts. Inside this folder create one blade view file named app.blade.php file. Now go to resources/views/layouts and open app.blade.php file. Then update the following code into your app.blade.php file as follow:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="csrf-token" content="{{ csrf_token() }}"> <title>Laravel Vue JS FullCalendar Example</title> <script src="{{ asset('js/app.js') }}" defer></script> <link href="{{ asset('css/app.css') }}" rel="stylesheet"> @stack('fontawesome') </head> <body> <div id="app"> <main class="py-4"> @yield('content') </main> </div> </body> </html> |
Now, go to resources/views/ and open welocome.blade.php. Then update the following code into your welcome.blade.php file as follow:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
@extends('layouts.app') @section('content') <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="card"> <div class="card-header">Laravel Vue JS FullCalendar Example</div> <div class="card-body"> <fullcalendar-component></fullcalendar-component> </div> </div> </div> </div> </div> @endsection |
Step 9: Run Development Server
Now we are ready to run our example so lets start the development server using following artisan command –
1 2 3 4 5 |
npm run dev or npm run watch |