安装拉拉维尔空间/权限后获取错误异常

我正在尝试安装该程序包,以帮助管理我在应用程序中的角色和权限。我一直遇到以下问题。根据文档,要安装 ,请运行此命令spatie/laravel-permissionLaravel permission


composer require spatie/laravel-permission

但是,当我这样做时,我收到此错误:


> @php artisan package:discover --ansi


   ErrorException  : Trying to access array offset on value of type null


  at /home/anto/encomm/projects/vendor/spatie/laravel-permission/src/PermissionServiceProvider.php:61

    57|     protected function registerModelBindings()

    58|     {

    59|         $config = $this->app->config['permission.models'];

    60| 

  > 61|         $this->app->bind(PermissionContract::class, $config['permission']);

    62|         $this->app->bind(RoleContract::class, $config['role']);

    63|     }

    64| 

    65|     protected function registerBladeExtensions()


  Exception trace:


  1   Illuminate\Foundation\Bootstrap\HandleExceptions::handleError()

      /home/anto/encomm/projects/vendor/spatie/laravel-permission/src/PermissionServiceProvider.php:61


  2   Spatie\Permission\PermissionServiceProvider::registerModelBindings()

      /home/anto/encomm/projects/vendor/spatie/laravel-permission/src/PermissionServiceProvider.php:36


  Please use the argument -v to see more details.

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1


Installation failed, reverting ./composer.json to its original content.

以下是我的文件的内容:composer.json


    "name": "laravel/laravel",

    "type": "project",

    "description": "The Laravel Framework.",

    "keywords": [

        "framework",

        "laravel"

    ],

    "license": "MIT",

    "require": {

        "php": "^7.4",

        "fideloper/proxy": "^4.0",

        "laravel/framework": "^6.2",

        "laravel/passport": "^8.2",

        "laravel/tinker": "^2.0",

        "laravel/ui": "^1.1",

        "owen-it/laravel-auditing": "^9.3",

        "sudiptpa/guid": "^1.0",

        "unisharp/laravel-filemanager": "^2.0"

    },


慕田峪9158850
浏览 76回答 1
1回答

翻阅古今

运行第一条语句后,您需要对文件进行一些更改vendor/spatie/laravel-permission/src/PermissionServiceProvider.phpcomposer require spatie/laravel-permission这是第 61/62 行的实际代码:$this->app->bind(PermissionContract::class, $config['permission']);$this->app->bind(PermissionContract::class, $config['role']);需要更改以下内容:$this->app->bind(PermissionContract::class, isset($config['permission']));$this->app->bind(PermissionContract::class, isset($config['role']));之后,更改再次运行,仅此而已。在最新版本的 PHP 上,您必须使用 isset() 检查变量是否为空:composer require spatie/laravel-permission
打开App,查看更多内容
随时随地看视频慕课网APP