bezhanSalleh / filament-shield

The easiest and most intuitive way to add access management to your Filament Admin Resources, Pages & Widgets through `spatie/laravel-permission`
MIT License
1.29k stars 167 forks source link

BezhanSalleh\FilamentShield\FilamentShield::getLocalizedPageLabel(): Argument #1 ($page) must be of type string, array given, #311

Closed kleinertjusk closed 5 months ago

kleinertjusk commented 5 months ago

Bug Report: Issue with FilamentShield after Composer Update

Environment:

Description: After performing a composer update and ensuring all dependencies are up-to-date, an error occurs when attempting to create or edit a role. The error message is as follows:

BezhanSalleh\FilamentShield\FilamentShield::getLocalizedPageLabel(): Argument #1 ($page) must be of type string, array given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 355

Steps To Reproduce:

  1. Run composer update to update all dependencies.
  2. Try to create or edit a role in the application.
  3. Encounter the error mentioned above.

Expected Behavior: The creation or editing of roles should proceed without any errors.

Actual Behavior: An error is thrown regarding a type mismatch in FilamentShield::getLocalizedPageLabel().

Additional Information: Here is the relevant plugin code that might be related to the issue:

<?php

namespace Test\NotificationMailSettings;

use Filament\Contracts\Plugin;
use Filament\Panel;

class NotificationMailSettingsPlugin implements Plugin
{
    private const ID = 'NotificationMailSettings';

    private const RESOURCES = [
        NotificationMailSettingsResource::class,
    ];

    private const PAGES = [
        NotificationMailSettingsResource\Pages\CreateNotificationMailSettings::class,
        NotificationMailSettingsResource\Pages\EditNotificationMailSettings::class,
        NotificationMailSettingsResource\Pages\ListNotificationMailSettings::class,
    ];

    public function getId(): string
    {
        return self::ID;
    }

    public function register(Panel $panel): void
    {
        $panel
            ->resources(self::RESOURCES)
            ->pages(self::PAGES);
    }

    public function boot(Panel $panel): void
    {
        //...
    }

    public static function make(): static
    {
        return app(static::class);
    }
}
eelco2k commented 5 months ago

I'm having the same issue in filament v3.2.1 in version v3.1.42 it all works

eelco2k commented 5 months ago

after reverting to v3.1.42 and modifying the composer lock file with only the version v3.1.42 to the latest v3.2.1 and then composer install i get no errors.

So it's not related to filament itself. after upgrading online filament v3.2.1 via composer and confirmed working version of filament shield. I did a "composer update"

These were my package updates:

Lock file operations: 1 install, 27 updates, 0 removals
  - Upgrading althinect/filament-spatie-roles-permissions (v2.2.9 => v2.2.10)
  - Upgrading bezhansalleh/filament-language-switch (3.0.3 => 3.0.4)
  - Upgrading bezhansalleh/filament-shield (3.1.2 => 3.1.3)
  - Upgrading filament/actions (v3.2.1 d615834 => v3.2.1 200073b)
  - Upgrading filament/filament (v3.2.1 a9da0c9 => v3.2.1 375236c)
  - Upgrading filament/forms (v3.2.1 3eb6145 => v3.2.1 cd00ace)
  - Upgrading filament/infolists (v3.2.1 2515985 => v3.2.1 fc29971)
  - Upgrading filament/notifications (v3.2.1 4f5634f => v3.2.1 eaf2ecc)
  - Upgrading filament/spatie-laravel-settings-plugin (v3.2.1 d26f397 => v3.2.1 6988a6f)
  - Upgrading filament/spatie-laravel-translatable-plugin (v3.2.1 9a0d80a => v3.2.1 cb2f42b)
  - Upgrading filament/support (v3.2.1 332308f => v3.2.1 cf74fe9)
  - Upgrading filament/tables (v3.2.1 9efcf3f => v3.2.1 1bc4a06)
  - Upgrading husam-tariq/filament-database-schedule (v2.0.1 => v2.0.2)
  - Upgrading laravel-lang/attributes (2.9.1 => 2.9.2)
  - Upgrading laravel-lang/lang (14.2.0 => 14.2.3)
  - Upgrading meilisearch/meilisearch-php (v1.5.0 => v1.6.0)
  - Upgrading mollie/laravel-cashier-mollie (v2.11.0 => v2.11.1)
  - Upgrading noxoua/filament-activity-log (v2.1.92 => v2.2.0)
  - Locking openspout/openspout (v4.23.0)
  - Upgrading pestphp/pest (v2.30.0 => v2.31.0)
  - Upgrading pestphp/pest-plugin-arch (v2.6.0 => v2.6.1)
  - Upgrading phpdocumentor/type-resolver (1.7.3 => 1.8.0)
  - Upgrading spatie/image (3.3.3 => 3.3.4)
  - Upgrading spatie/laravel-backup (8.4.1 => 8.5.0)
  - Upgrading spatie/laravel-ignition (2.4.0 => 2.4.1)
  - Upgrading spatie/laravel-medialibrary (11.0.4 => 11.0.5)
  - Upgrading spatie/laravel-package-tools (1.16.1 => 1.16.2)
  - Upgrading tapp/filament-auditing (v3.0.2 => v3.0.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 27 updates, 0 removals
  - Downloading husam-tariq/filament-database-schedule (v2.0.2)
  - Upgrading spatie/laravel-package-tools (1.16.1 => 1.16.2): Extracting archive
  - Upgrading filament/support (v3.2.1 332308f => v3.2.1 cf74fe9): Extracting archive
  - Installing openspout/openspout (v4.23.0): Extracting archive
  - Upgrading filament/actions (v3.2.1 d615834 => v3.2.1 200073b): Extracting archive
  - Upgrading filament/notifications (v3.2.1 4f5634f => v3.2.1 eaf2ecc): Extracting archive
  - Upgrading filament/infolists (v3.2.1 2515985 => v3.2.1 fc29971): Extracting archive
  - Upgrading filament/forms (v3.2.1 3eb6145 => v3.2.1 cd00ace): Extracting archive
  - Upgrading filament/tables (v3.2.1 9efcf3f => v3.2.1 1bc4a06): Extracting archive
  - Upgrading filament/filament (v3.2.1 a9da0c9 => v3.2.1 375236c): Extracting archive
  - Upgrading althinect/filament-spatie-roles-permissions (v2.2.9 => v2.2.10): Extracting archive
  - Upgrading bezhansalleh/filament-language-switch (3.0.3 => 3.0.4): Extracting archive
  - Upgrading bezhansalleh/filament-shield (3.1.2 => 3.1.3): Extracting archive
  - Upgrading phpdocumentor/type-resolver (1.7.3 => 1.8.0): Extracting archive
  - Upgrading filament/spatie-laravel-settings-plugin (v3.2.1 d26f397 => v3.2.1 6988a6f): Extracting archive
  - Upgrading filament/spatie-laravel-translatable-plugin (v3.2.1 9a0d80a => v3.2.1 cb2f42b): Extracting archive
  - Upgrading husam-tariq/filament-database-schedule (v2.0.1 => v2.0.2): Extracting archive
  - Upgrading laravel-lang/lang (14.2.0 => 14.2.3): Extracting archive
  - Upgrading laravel-lang/attributes (2.9.1 => 2.9.2): Extracting archive
  - Upgrading meilisearch/meilisearch-php (v1.5.0 => v1.6.0): Extracting archive
  - Upgrading mollie/laravel-cashier-mollie (v2.11.0 => v2.11.1): Extracting archive
  - Upgrading noxoua/filament-activity-log (v2.1.92 => v2.2.0): Extracting archive
  - Upgrading pestphp/pest-plugin-arch (v2.6.0 => v2.6.1): Extracting archive
  - Upgrading pestphp/pest (v2.30.0 => v2.31.0): Extracting archive
  - Upgrading spatie/laravel-backup (8.4.1 => 8.5.0): Extracting archive
  - Upgrading spatie/laravel-ignition (2.4.0 => 2.4.1): Extracting archive
  - Upgrading spatie/image (3.3.3 => 3.3.4): Extracting archive
  - Upgrading spatie/laravel-medialibrary (11.0.4 => 11.0.5): Extracting archive
  - Upgrading tapp/filament-auditing (v3.0.2 => v3.0.3): Extracting archive

After upgrading I got the same error...

So it looks like i comes from some other packages in this list.

marcosmarcolin commented 5 months ago

Hello, it is not the Filament version, but a change to this PR: https://github.com/bezhanSalleh/filament-shield/pull/310, where it calls getLocalizedPageLabel.

An array is being passed to where a string is expected.

I think it's this line: https://github.com/bezhanSalleh/filament-shield/pull/310/files#diff-a52c07c4daa9b4eecb7a75164346bd5b31698d81e2b0bb3222134675d73e9533R415

eelco2k commented 5 months ago

@marcosmarcolin you are absolutely right. keeping filament-shield at version 3.1.2 and updating the rest gives no error so the issue is in the latest version 3.1.3

for now i keep this version fixed @ v3.1.2 via:

composer require bezhansalleh/filament-shield:3.1.2

bezhanSalleh commented 5 months ago

@kleinertjusk @marcosmarcolin could you do me a favor and submit a minimum reproducable repo. or even the result of running the following would help in tinker or tinkerwell. Cause i'm running on a couple my own apps, and just did a test on a fresh filament demo repo and couldn't reproduce it.

use BezhanSalleh\FilamentShield\Facades\FilamentShield;
FilamentShield::getPages();
kleinertjusk commented 5 months ago

@kleinertjusk @marcosmarcolin could you do me a favor and submit a minimum reproducable repo. or even the result of running the following would help in tinker or tinkerwell. Cause i'm running on a couple my own apps, and just did a test on a fresh filament demo repo and couldn't reproduce it.

use BezhanSalleh\FilamentShield\Facades\FilamentShield;
FilamentShield::getPages();
use BezhanSalleh\FilamentShield\Facades\FilamentShield;\
. FilamentShield::getPages();
= []
marcosmarcolin commented 5 months ago

@bezhanSalleh

could you do me a favor and submit a minimum reproducable repo. or even the result of running the following would help in tinker or tinkerwell.

I managed to solve it by publishing the RoleResource again with php artisan shield:publish, where it updated the Resource in app/Filament/Resources/Shield/RoleResource.php.

Because it became incompatible with the latest plugin update.

Firstly, I only updated getPageOptions()and getWidgetOptions() which also worked.

image

I suggest generating and replacing with Resource with artisan.

bezhanSalleh commented 5 months ago

Guessing all of you have published the resource? And that's the cause for this issue. Republishing it would fix your issues.