本文介绍了Laravel 5.6-Uncaught RuntimeException:尚未设置外观根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在课堂上尝试使用 Illuminate \ Http \ Request 时,出现以下错误.

I am getting following error when I try to use Illuminate\Http\Request 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): 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

相关课程:

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',
        ];
    }

}

我在做什么错了?

推荐答案

您需要创建一个新的应用程序容器,然后将其绑定到Facade.

You need to create a new app container and then bind it to the 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);

内腔

:bootstrap/app.php

in lumen:bootstrap/app.php

$app->withFacades();

祝你好运!

这篇关于Laravel 5.6-Uncaught RuntimeException:尚未设置外观根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 02:16