Level 5
If you had a relationship on the User model for Profile, you could do the following:
User::create([...])->profile()->create([...]);
Hi, I am trying to create a user with a profile table related so far...
$newUser = User::create([
'name' => 'daniel',
'email' => '[email protected]',
'password' => Hash::make(123),
]);
Profile::create([
'user_id' => $newUser->id,
'nombre' => 'Adminer',
'apellido' => 'Jhonson',
]);
this is working but I thing there should be a better way to do it... can some one help me? am using for a role this one
$newUser->role()->attach(1);
I love this way
so I want to make something like this
$newUser->Profile()->attach($newUser->id); // this is my idea to create an attached table to that ID user
thanks in advance for your help
If you had a relationship on the User model for Profile, you could do the following:
User::create([...])->profile()->create([...]);
Please or to participate in this conversation.