英文:
How to add fullcallendar to a laravel app
问题
I am trying to integrate fullcalendar 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.
英文:
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.
答案1
得分: 1
我自己找到了。你需要做的是进入 laravel_app/config/global/pages.php
,并将以下内容添加到主数组中:
'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',
),
),
),
),
创建一个路由:
// calendar
Route::get('/calendar', [CalendarController::class, 'index']);
创建一个控制器:
<?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']);
}
}
在 laravel_app/resources/views/pages/
中创建 calendar.blade.php
,并从 demo1 calendar.html
添加日历和模态框。
就是这样,希望对其他人有帮助,因为 Metronic 在 Laravel 上的文档并不是很清晰。
英文:
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.
答案2
得分: 0
你不应该从你的控制器中添加资源。你使用的代码不是PHP/Laravel代码,所以它不会工作。
你应该总是在你的Blade文件中添加资源,像这样使用脚本标签:
<script src='https://cdn.jsdelivr.net/npm/fullcalendar@6.1.7/index.global.min.js'></script>
然后你可以像官方文档建议的那样使用fullcalendar:https://fullcalendar.io/docs/initialize-globals
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论