Laravel 5.6 - 未捕获的运行时异常:尚未设置外观根
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49818102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.6 - Uncaught RuntimeException: A facade root has not been set
提问by Sasha
I am getting following error when I try to use Illuminate\Http\Requestin my class.
当我尝试在我的班级中使用Illuminate\Http\Request时出现以下错误。
Error:
错误:
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): Illuminate\Support\Facades\Facade::__callStatic('replaceNamespac...', Array)
#1 /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(373): Illuminate\Foundation\Exceptions\Handler->registerErrorViewPaths()
#2 /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(288): Illuminate\Foundation\Exceptions\Handler->renderHttpException(Object(Symfony\Component\HttpKernel\Exception\HttpException))
#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
The class in question:
有问题的班级:
namespace App\App\Components;
use Illuminate\Http\Request;
/**
* 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',
];
}
}
What am I doing wrong here?
我在这里做错了什么?
采纳答案by Adam Kozlowski
You need to create a new app container and then bind it to the Facade.
您需要创建一个新的应用程序容器,然后将其绑定到 Facade。
use \Illuminate\Container\Container as Container;
use \Illuminate\Support\Facades\Facade as Facade;
/**
* Setup a new app instance container
*
* @var Illuminate\Container\Container
*/
$app = new Container();
$app->singleton('app', 'Illuminate\Container\Container');
/**
* Set $app as FacadeApplication handler
*/
Facade::setFacadeApplication($app);
in lumen: bootstrap/app.php
在流明:bootstrap/app.php
$app->withFacades();
Good luck!
祝你好运!
回答by writeNow
I know this is old but maybe it will help someone. I ran into this problem after I was fiddling with my app/config.php file. I added some options and accidentally put a semi-colon instead of a comma after it. I had:
我知道这很旧,但也许它会帮助某人。在我摆弄我的 app/config.php 文件后,我遇到了这个问题。我添加了一些选项,但不小心在它后面放了一个分号而不是逗号。我有:
'vapid_public_key' => env('VAPID_PUBLIC_KEY'); <--- offending semi-colon
'vapid_private_key' => env('VAPID_PRIVATE_KEY'),
Changed it to the proper comma and everything works as expected.
将其更改为正确的逗号,一切都按预期进行。
回答by kerohzenn
I know that this is not the best answer, but it works to me.
我知道这不是最好的答案,但它对我有用。
there is some problem with permission, i do 777 to all laravel project and now it works.
权限有问题,我对所有 Laravel 项目都执行了 777 操作,现在它可以工作了。
some file(s) or directory is the problem, i need a quick fix, but it's not goot to set all 777.
某些文件或目录是问题所在,我需要快速修复,但设置所有 777 并不合适。