Skip to content

Commit

Permalink
Updates regarding WithoutModelEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
drbyte authored Aug 27, 2024
1 parent 43550a1 commit 631799b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/advanced-usage/seeding.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ weight: 2

You may discover that it is best to flush this package's cache **BEFORE seeding, to avoid cache conflict errors**.

And if you use the `WithoutModelEvents` trait in your seeders, flush it **AFTER seeding as well**.
And if you use the `WithoutModelEvents` trait in your seeders, flush it **AFTER creating any roles/permissions as well, before assigning or granting them.**.

```php
// reset cached roles and permissions
Expand Down Expand Up @@ -40,6 +40,10 @@ class RolesAndPermissionsSeeder extends Seeder
Permission::create(['name' => 'publish articles']);
Permission::create(['name' => 'unpublish articles']);

// update cache to know about the newly created permissions (required if using WithoutModelEvents in seeders)
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();


// create roles and assign created permissions

// this can be done as separate statements
Expand Down

0 comments on commit 631799b

Please sign in to comment.