Cinek
161
2
Laravel

Model events in database seeder

Posted 8 months ago by Cinek

Hi, I have one confusion. I have 2 models: User and Group. Group have user_id which means owner of this group. I fill this ID in GroupObserver in creating function

$group->user()->associate(Auth::user());

I have problem because it will fail:

        factory(\App\Models\Group::class, 10)->create();

while seeding there is not logged user. I assigned user to group in GroupFactory and disable all events on Group model but I think there's a better way to workarround this problem.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.