-
Notifications
You must be signed in to change notification settings - Fork 89
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
Can't save meta with factory builder/seeder #27
Comments
While I've had the same issue, I don't have separate *Meta classes - I've gotten around doing it this way: SupplierFactory.php
SuppliersTableSeeder.php
As you can see, saving of metadata can't be done in the same step as creating given Model, but instead we have to utilize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I create a table seeder for a table that uses metable, the meta columns don't get translated into key/value pairs on the related table. For example:
In database/factories/ModelFactory.php:
If I were to call (via artisan tinker): factory(App\Models\Business::class,10)->create(), I get this error:
What I have to do instead as a workaround, is setting the meta data into a separate factory definition:
And then calling:
factory(App\Models\Business::class,10)->create()->each(function ($business) { $business->setMeta(factory(App\Models\BusinessMeta::class)->make()->toArray()); $business->save(); });
If there's a way to make a direct call to factory()->create() work without the each(), it would make things simpler.
The text was updated successfully, but these errors were encountered: