Level 1
I managed to find this link and it works like a charm, if anyone wants it.
https://stefanzweifel.io/posts/2020/09/17/nested-states-in-laravel-8-database-factories
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Question is about user factory and automatic creation of child table records. So far, I have been creating usual way. Creating users then creating posts.
User::factory()
->has(Post::factory()->count(10))
->create();
Now... I have a different situation:
Users
- hasMany Roles
- hasOne Profile which
- hasOne ProfileConfigs
- hasMany OtherConfigs
Can I make automatic creation of all downward records based on rules (which I guess is separate factories), but to be executed at once when user factory is started? How it is proper way to be done?
Please or to participate in this conversation.