Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0.0] Cannot assign null to property Spatie\Permission\PermissionRegistrar::$teamsKey of type string #2535

Closed
geniqtech opened this issue Nov 2, 2023 · 4 comments
Labels

Comments

@geniqtech
Copy link

Was trying to upgrade from v5.11.1 to v6.0.0 but wasn't able to complete the upgrade process.

Versions

  • spatie/laravel-permission package version: 5.11.1
  • laravel/framework package: 10.30.1
  • PHP version: 8.2.3

To Reproduce
Steps to reproduce the behavior:

  1. Update composer.json => "spatie/laravel-permission": "^6.0.0"
  2. Run "composer update"
  3. The following error occurs:
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 1 update, 0 removals
  - Upgrading spatie/laravel-permission (5.11.1 => 6.0.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Downloading spatie/laravel-permission (6.0.0)
  - Upgrading spatie/laravel-permission (5.11.1 => 6.0.0): Extracting archive
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   TypeError

  Cannot assign null to property Spatie\Permission\PermissionRegistrar::$teamsKey of type string

  at vendor\spatie\laravel-permission\src\PermissionRegistrar.php:69
     65▕     {
     66▕         $this->cacheExpirationTime = config('permission.cache.expiration_time') ?: \DateInterval::createFromDateString('24 hours');
     67▕
     68▕         $this->teams = config('permission.teams', false);
  ➜  69▕         $this->teamsKey = config('permission.column_names.team_foreign_key');
     70▕
     71▕         $this->cacheKey = config('permission.cache.key');
     72▕
     73▕         $this->pivotRole = config('permission.column_names.role_pivot_key') ?: 'role_id';

  1   vendor\spatie\laravel-permission\src\PermissionRegistrar.php:61
      Spatie\Permission\PermissionRegistrar::initializeCache()

  2   [internal]:0
      Spatie\Permission\PermissionRegistrar::__construct()

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

drbyte commented Nov 2, 2023

Hmmm. We might need to code a fallback for the missing key.

As a workaround, I'd suggest taking the config file from this repo and merge its updates into your own app's old config file.
That should get around the issue.

Please report back, as your feedback will help determine the best "fix" to build into the package.

@geniqtech
Copy link
Author

@drbyte Thank you very much for your response.
Following your advice, I added the following to permissions.php (under section "column_names") and the problem was solved.

/*
 * Change this if you want to use the teams feature and your related model's
 * foreign key is other than `team_id`.
 */

 'team_foreign_key' => 'team_id',

@drbyte
Copy link
Collaborator

drbyte commented Nov 2, 2023

@erikn69 Do you think it's best to just declare public string $teamsKey; as nullable? Or have the config lookup default to 'team_id' instead of null?

@drbyte drbyte changed the title Unable to upgrade to v6.0.0 [6.0.0] Cannot assign null to property Spatie\Permission\PermissionRegistrar::$teamsKey of type string Nov 2, 2023
@drbyte drbyte added the bug label Nov 2, 2023
@erikn69
Copy link
Contributor

erikn69 commented Nov 6, 2023

Or have the config lookup default to 'team_id' instead of null?

I think it would be better, but it shouldn't affect either

private ?string $roleClass = null;

@drbyte drbyte closed this as completed in 9e83ebe Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants