Something like this: https://laravel.com/docs/8.x/database-testing#factory-callbacks
Register the callbacks and do the rest.
Summer Sale! All accounts are 50% off this week.
I am creating a factory for a model Post for testing. I have a seed for set tags already in the database. I want to be able to attach Tags (polymorphic many-to-many relationship) to a post automatically after creating it.
How can I do that in the PostFactory class, so that when a post is created, it is automatically attached with some tags?
Note- my classes are not exactly Posts and Tags but something else - I have just abstracted them for the purposes of relating to examples found commonly in Laravel.
Something like this: https://laravel.com/docs/8.x/database-testing#factory-callbacks
Register the callbacks and do the rest.
Please or to participate in this conversation.