我正在尝试为一个类注册别名,但 Laravel 找不到该类,我可以直接在我的 Controller 中引用该类,所以我知道它已正确加载。
这是我的代码:
'aliases' => array(
'FrontendAssets' => 'Lib\FrontendAssets',
)
我要为其创建别名的类
class FrontendAssets{
protected static $styles = [];
protected static $scripts = [];
public static function styles(){
return static::assets(static::$styles);
}
public static function addStyle($style){
static::$styles[] = $style;
}
public static function scripts(){
$scripts = static::assets(static::$scripts);
return $scripts;
}
public static function addScript($script){
static::$scripts[] = $script;
}
public static function assets($assets){
return array_map(function ($asset){
return $asset;
}, array_unique($assets));
}
}
这就是我要在我的 Controller 中调用的内容
FrontendAssets::assets();
我已经尝试添加 namespace ,但仍然不开心。
如果我使用 \FrontendAssets::assets();
在我的 Controller 中,我可以使用这个类,所以我知道它已经被加载了
最佳答案
php artisan config:clear
也可能有帮助。如果您之前使用 config:cache
缓存了配置文件,因为别名是在应用程序配置中定义的。
关于php - Laravel 别名找不到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26527930/