You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are three major terms that Laravel Populator introduces:
@@ -137,6 +161,42 @@ Populator::make('v1')
137
161
138
162
This will call your populator and all it's defined bundles (more information in the Bundles section)
139
163
164
+
### Reversing a populator
165
+
The records inserted by a populator can be removed if [tracking](#enabling-tracking) is enabled when the populator was run.
166
+
167
+
```php
168
+
Populator::make('v1')
169
+
->bundles([//your bundles to reverse or leave blank for all bundles in the populator])
170
+
->rollback()
171
+
```
172
+
173
+
Rollbacks will filter using the following condition
174
+
175
+
1. Population populator name
176
+
2. Bundle model classes
177
+
3. Bundle name
178
+
179
+
This allows you to control what bundles are rolled back from a populator.
180
+
181
+
For example you can rollback a subset of the bundles from the populator
182
+
183
+
```php
184
+
185
+
Populator::make('initial')
186
+
->bundles([
187
+
Bundle::make(User::class),
188
+
Bundle::make(Post::class),
189
+
])
190
+
->call();
191
+
//User and Post entries now exist
192
+
193
+
Populator::make('initial')
194
+
->bundles([Bundle::make(Post::class)])
195
+
->rollback();
196
+
//Post entries were removed
197
+
```
198
+
199
+
140
200
### Environment
141
201
Populators can be set to be executed only on specific environments. You might most likely want to seed different data for your local environment and your production environment.
142
202
@@ -211,6 +271,22 @@ Bundle::make(User::class)
211
271
...
212
272
```
213
273
274
+
## Override insert behavior
275
+
276
+
If you need to customize the insertion behavior for records you can call `performInsertUsing()` on a bundle.
277
+
278
+
For example, to perform an updateOrCreate instead of an insert
0 commit comments