skip to Main Content

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

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

Undefined constant "AppHttpControllershelpers"
CODE:

<?php
namespace AppHttpControllers;

use AppModelsUser;
use IlluminateHttpRequest;

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.

2

Answers


  1. Chosen as BEST ANSWER

    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 AppHttpControllers;
    
    use AppModelsUser;
    use IlluminateHttpRequest;
    
    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.


  2. 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/[email protected]/index.global.min.js'></script>
    

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search