spatie/laravel-permission

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

moijafcor opened this issue · 6 comments

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

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

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.

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?

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.

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.

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