@gavin_r just add the following after you have created the $user
$team = $user->teams()->create([
'name' => 'New Team',
]);
see https://laravel.com/docs/8.x/eloquent-relationships#the-create-method
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
As part of a seeder I'd like to create a specific user. If I do something like this:
$user = new User();
$user->name = 'John Smith';
$user->email = '[email protected]';
$user->email_verified_at = now();
$user->password = '...';
$user->save();
... the user gets created but the associated Team does not. Is there a better way to do this - somehow can I call the same underlying logic that Jetstream/Fortify calls when a user is created? Where can I find that?
Thanks!
Please or to participate in this conversation.