本文介绍了Laravel 5.6 - 未捕获的运行时异常:尚未设置外观根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在课堂上尝试使用 IlluminateHttpRequest 时遇到以下错误.
I am getting following error when I try to use IlluminateHttpRequest in my class.
错误:
PHP Fatal error: Uncaught RuntimeException: A facade root has not been set. in /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:218
Stack trace:
#0 /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(396): IlluminateSupportFacadesFacade::__callStatic('replaceNamespac...', Array)
#1 /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(373): IlluminateFoundationExceptionsHandler->registerErrorViewPaths()
#2 /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(288): IlluminateFoundationExceptionsHandler->renderHttpException(Object(SymfonyComponentHttpKernelExceptionHttpException))
#3 /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(187): Illumina in /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 218
有问题的课程:
namespace AppAppComponents;
use IlluminateHttpRequest;
/**
* This class will be used to build menu for admin panel based on the user role
*/
class AdminPanelMenu {
static function menu(Request $request){
$user = $request->user();
if($user->hasRole['super_admin'])
return self::superAdmin();
if($user->hasRole['admin'])
return self::admin();
if($user->hasRole['user'])
return self::user();
return [];
}
private static function superAdmin()
{
return [
'MAIN NAVIGATION',
];
}
private static function admin()
{
return [
'MAIN NAVIGATION',
];
}
private static function user()
{
return [
'MAIN NAVIGATION',
];
}
}
我在这里做错了什么?
推荐答案
您需要创建一个新的应用容器,然后将其绑定到 Facade.
You need to create a new app container and then bind it to the Facade.
use IlluminateContainerContainer as Container;
use IlluminateSupportFacadesFacade as Facade;
/**
* Setup a new app instance container
*
* @var IlluminateContainerContainer
*/
$app = new Container();
$app->singleton('app', 'IlluminateContainerContainer');
/**
* Set $app as FacadeApplication handler
*/
Facade::setFacadeApplication($app);
流明:引导程序/app.php
in lumen:bootstrap/app.php
$app->withFacades();
祝你好运!
这篇关于Laravel 5.6 - 未捕获的运行时异常:尚未设置外观根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!