-
Notifications
You must be signed in to change notification settings - Fork 3
Add PolicySeeder #1178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: create-generic-policy-schemas
Are you sure you want to change the base?
Add PolicySeeder #1178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| namespace Database\Seeders; | ||
|
|
||
| use App\Policy; | ||
| use Carbon\CarbonImmutable; | ||
| use Illuminate\Database\Seeder; | ||
|
|
||
| class PolicySeeder extends Seeder { | ||
| public function run() { | ||
| Policy::create( | ||
| [ | ||
| 'policy_type' => 'terms-of-use', | ||
| 'active_from' => CarbonImmutable::createFromDate(2026, 06, 01), | ||
| 'content_vue_file' => 'terms-of-use/example.vue', | ||
| ] | ||
| ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this will create a new policy, or fail if the policy already exists. If multiple seeders are run in the future, I think a failed Seeder will prevent subsequent seeders from running, which is likely not what we want. From my quick searching, it's often recommended to create seeders in an idempotent way (i.e. running the seeder multiple times will result in the same database state). https://oneuptime.com/blog/post/2026-02-03-laravel-database-seeding/view recommends using Alternatively/additionally, you could use the |
||
| } | ||
|
Comment on lines
+10
to
+18
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For testing purposes, would it be useful to have more than one current policy? Maybe also a superseded policy? I'm also happy if we add these at a later stage, though. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a
CarbonImmutableinstance here works, but makes it trickier to usefirstOrCreate()orupdateOrCreate()methods (see other comment as to why you would want to use those methods). This is because (emphasis mine):And explained using tinker:
To address this you could either:
'active_from' => '2026-06-01',)CarbonImmutable::createMidnightDate()method