Skip to content

Commit 631799b

Browse files
authored
Updates regarding WithoutModelEvents
1 parent 43550a1 commit 631799b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

docs/advanced-usage/seeding.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ weight: 2
77

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

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

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

43+
// update cache to know about the newly created permissions (required if using WithoutModelEvents in seeders)
44+
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
45+
46+
4347
// create roles and assign created permissions
4448

4549
// this can be done as separate statements

0 commit comments

Comments
 (0)