I am relatively new to laravel and have a project that requires a bit of manual configuration.
Background:
- Working with Authentication Scaffolding (handles the user registration and login)
- I have two tables: Profile and Users.
- All Users have one Profile.
- But not all Profiles have a user.
Setup: Profile table => id, name, avatar, etc. User Table => profile_id, email, password
Since the Laravel Auth (Scaffold) handles the Registration and Login. I am trying to save data into the Profile table before saving the user table.
protected function create(array $data)
{
$profile = Profile::create
([
'slug' => $data['name'],
'name' => $data['name'],
]);
$user = User::create
([
'profile_id' => $profile->id,
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
return $user;
}
But this is not working. And the error message is telling me there is no profile_id assigned in the query.
What am I doing wrong?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire