1namespace App\Http\Controllers;
2
3use Illuminate\Http\Request;
4use Calendar;
5use App\Event;
6
7class EventController extends Controller
8{
9 public function index()
10 {
11 $events = [];
12 $data = Event::all();
13 if($data->count()) {
14 foreach ($data as $key => $value) {
15 $events[] = Calendar::event(
16 $value->title,
17 true,
18 new \DateTime($value->start_date),
19 new \DateTime($value->end_date.' +1 day'),
20 null,
21 // Add color and link on event
22 [
23 'color' => '#f05050',
24 'url' => 'pass here url and any route',
25 ]
26 );
27 }
28 }
29 $calendar = Calendar::addEvents($events);
30 return view('fullcalendar', compact('calendar'));
31 }
32}
33
1'providers' => [
2 .....
3 .....
4 MaddHatter\LaravelFullcalendar\ServiceProvider::class,
5],
6'aliases' => [
7 .....
8 .....
9 'Calendar' => MaddHatter\LaravelFullcalendar\Facades\Calendar::class,
10]
11
1@extends('layouts.app')
2
3@section('style')
4<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
5<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/>
6@endsection
7
8@section('content')
9<div class="container">
10 <div class="row">
11 <div class="col-md-8 col-md-offset-2">
12 <div class="panel panel-default">
13 <div class="panel-heading">Full Calendar Example</div>
14
15 <div class="panel-body">
16 {!! $calendar->calendar() !!}
17 </div>
18 </div>
19 </div>
20 </div>
21</div>
22@endsection
23
24@section('script')
25<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
26<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
27{!! $calendar->script() !!}
28@endsection
1Route::get('/', function () {
2 return view('welcome');
3});
4
5Auth::routes();
6
7Route::get('/home', 'HomeController@index')->name('home');
8Route::get('events', 'EventController@index');
9
1use Illuminate\Support\Facades\Schema;
2use Illuminate\Database\Schema\Blueprint;
3use Illuminate\Database\Migrations\Migration;
4class CreateEventsTable extends Migration
5{
6 /**
7 * Run the migrations.
8 *
9 * @return void
10 */
11 public function up()
12 {
13 Schema::create('events', function (Blueprint $table) {
14 $table->increments('id');
15 $table->string('title');
16 $table->date('start_date');
17 $table->date('end_date');
18 $table->timestamps();
19 });
20 }
21 /**
22 * Reverse the migrations.
23 *
24 * @return void
25 */
26 public function down()
27 {
28 Schema::drop("events");
29 }
30}
31