0

I am trying to integrate fullcallendar in a laravel10 + Metronic app

helpers.addVendors(['fullcalendar']); called from controller gives error:

Undefined constant "App\Http\Controllers\helpers" CODE:

<?php
namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;

class CalendarController extends Controller
{
    public function index()
    {
        helpers.addVendors(['fullcalendar']);

        return view('pages/calendar')->with(['page'=>'calendar','section'=>'this_month']);
    }
}

How to add assets from controller? Documentation isn't that clear.

Thank you.

Sofnam
  • 35
  • 4

2 Answers2

1

I found it by myself. What you got to do is go to laravel_app/config/global/pages.php and add this to the main array :

'calendar' => array(
'title'  => 'Calendar modified',
'assets' => array(
    'custom' => array(
        'css' => array(
            'plugins/custom/flatpickr/flatpickr.bundle.css',
            'plugins/custom/fullcalendar/fullcalendar.bundle.css',
            'plugins/custom/datatables/datatables.bundle.css',
        ),

        'js' => array(
            'plugins/custom/flatpickr/flatpickr.bundle.js',
            'plugins/custom/fullcalendar/fullcalendar.bundle.js',
            'plugins/custom/datatables/datatables.bundle.js',

            'js/custom/apps/calendar/mycalendar.js',
        ),
    ),
),

Create a route

// calendar
Route::get('/calendar', [CalendarController::class, 'index']);

Create a controller

<?php
namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;

class CalendarController extends Controller
{
    public function index()
    {
        return view('pages/calendar')->with(['page'=>'calendar','section'=>'this_month']);
    }
}

Create calendar.blade.php in laravel_app/resources/views/pages/ and add calendar and modals from the demo1 calendar.html

That is all, hope it helps others, as the Metronic documentation on laravel is not that clear.

Sofnam
  • 35
  • 4
0

You should never add assets from your controller. Code you used is not PHP/laravel code, so it won't work.

You should always add assets in your blade file, in this case with script tag like this:

<script src='https://cdn.jsdelivr.net/npm/fullcalendar@6.1.7/index.global.min.js'></script>

Then you can use fullcalendar as it's official documentation suggests https://fullcalendar.io/docs/initialize-globals

Jerry
  • 61
  • 4
  • the thing is that i am using Metronic and i have to use exactly this calendar: https://preview.keenthemes.com/metronic8/demo1/apps/calendar.html – Sofnam May 22 '23 at 13:53
  • "_You should never add assets from your controller_" Why not? – brombeer May 22 '23 at 14:37