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

Access to undeclared static property Spatie\Permission\PermissionRegistrar::$pivotPermission #2577

Closed
moijafcor opened this issue Dec 13, 2023 · 6 comments

Comments

@moijafcor
Copy link

Describe the bug

Access to undeclared static property Spatie\Permission\PermissionRegistrar::$pivotPermission

blames

# xxxx_xx_xx_xxxxxx_create_permission_tables.php

6▕  use Spatie\Permission\PermissionRegistrar;

....

58▕ 
59▕         Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) {
60▕             $table->unsignedBigInteger(PermissionRegistrar::$pivotPermission);

defined in:

class PermissionRegistrar
{

    ....
    public string $pivotPermission;
    .....

Versions

laravel/framework                  v10.37.1 The Laravel Framework.
spatie/laravel-permission          6.2.0    Permission handling for Laravel 8.0 and up

*** Environment ***

  Laravel Version .......................................................................................................................... 10.37.1  
  PHP Version ............................................................................................................................... 8.1.13  
  Composer Version ........................................................................................................................... 2.4.4  

*** Database version: ***

MySQL 8

@drbyte
Copy link
Collaborator

drbyte commented Dec 13, 2023

If you look at your migration, you'll see that you're still using the old migration from before beginning your upgrade.
The new migration is quite different.
That means you haven't read the upgrade documentation and followed the steps to upgrade your use of the package to be compatible with the new version.
https://github.com/spatie/laravel-permission/blob/main/docs/upgrading.md#upgrade-essentials

@drbyte drbyte closed this as completed Dec 13, 2023
@moijafcor
Copy link
Author

moijafcor commented Dec 13, 2023

Sorry for the confusion. I did not upgrade this package because I just discovered it recently. What I did was a fresh install for a
new app hence I didn't assume a need to read the documentation's Upgrade section. But, maybe I messed up. Apologize for the bother.

@drbyte
Copy link
Collaborator

drbyte commented Dec 13, 2023

I'm puzzled about how you would get an old migration file on a new app.

How exactly did you do the install?

Or maybe did you install some other bundle by some other set of packages that maybe included an old version of this package?

@drbyte
Copy link
Collaborator

drbyte commented Dec 13, 2023

ie: I just installed a new Laravel app:

laravel new permtest
cd permtest
php artisan migrate

migration successful

then install this package to the app:

composer require spatie/laravel-permission:^6.0
php artisan vendor:publish  // choose Spatie Laravel Permission
php artisan migrate

migration successful

No errors.

And when I look at line 60 of my migration file it's completely different from the one you quoted a segment of above.

@moijafcor
Copy link
Author

moijafcor commented Dec 14, 2023

Yeap, it's rather confusing though.

This app I am referring to uses Laravel Jetstream with teams support, so maybe like I said, I may have messed up something somewhere while settling it up.

The issue appeared after upgrading PHP in order to satisfy another package requiring 8.1 or above.

Sorry for the bother. Appreciate your time and effort.

@drbyte
Copy link
Collaborator

drbyte commented Dec 15, 2023

Probably best to:

  • make sure composer.json mentions ^6.0 for this package, and double-check using composer outdated
  • delete the old migration for permissions/roles tables
  • re-publish the migration using php artisan vendor:publish
  • re-migrate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants