Skip to content

Permission seeder - PermissionDoesNotExist #2708

Answered by drbyte
basic-ph asked this question in Q&A
Discussion options

You must be logged in to vote

OH ... Maybe you're using use WithoutModelEvents;?

Try without that.

Or add a cache-flush after creating those permissions:

    use WithoutModelEvents;

    public function run(): void
    {
        // Reset cached roles and permissions
        app()[PermissionRegistrar::class]->forgetCachedPermissions();

        // create permissions
        Permission::create(['name' => 'edit articles']);
        Permission::create(['name' => 'delete articles']);
        Permission::create(['name' => 'publish articles']);
        Permission::create(['name' => 'unpublish articles']);

        // update cache
+        app()[PermissionRegistrar::class]->forgetCachedPermissions();

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@basic-ph
Comment options

@drbyte
Comment options

@drbyte
Comment options

Answer selected by basic-ph
@basic-ph
Comment options

@drbyte
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants