我正在尝试安装该程序包,以帮助管理我在应用程序中的角色和权限。我一直遇到以下问题。根据文档,要安装 ,请运行此命令spatie/laravel-permissionLaravel permissioncomposer 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 1Installation 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" },
1 回答
翻阅古今
TA贡献1780条经验 获得超5个赞
运行第一条语句后,您需要对文件进行一些更改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
- 1 回答
- 0 关注
- 75 浏览
添加回答
举报
0/150
提交
取消