我试图在没有作曲家自动加载的情况下加载助手
对于控制器,我使用:
use AppHelper;
效果很好,但是对于Blade的视图,我该如何加载?
在刀片视图中您可以用作 app helper :: call();
@php
$var = AppHelper::call();
@endphp
您可以做2种方法
解决方案1:使别名
在configapp.php
中将aliases
更改为
'aliases' => [
'App' => IlluminateSupportFacadesApp::class,
'Artisan' => IlluminateSupportFacadesArtisan::class,
'Auth' => IlluminateSupportFacadesAuth::class,
...................
'Helper' => AppHelper::class,
]
在刀片中使用
@php
$result = Helper::staticFunction();
// or
$helper = app(Helper::class);
$helper->functionName();
@endphp
解决方案2:
@php
$result = AppHelper::staticFunction();
// ot
$helper = app(AppHelper::class);
$helper->functionName();
@endphp
尝试清除caches
php artisan cache:clear
php artisan config:clear
php artisan route:clear