I am new to Laravel. I want to do like this when user register the account, the details will save into 2 database table. Based on the image given below, I want to link the relationship between id with user_id:
So when I go to phpmyadmin, I click at user_id it will redirect me to see the user table details based on the id.
Here is my code:
protected function create(array $data)
{
$user= User::create([
'username' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
$employee= Employee::create([
'username' => $data['name'],
'email' => $data['email'],
]);
return $user;
}
Does anyone know how to do that?
3
Answers
If you issue with creating the model using relationships. You can add
user_id
to data while creatingYou can define Eloquent One to One relation like this :
appModelsUser.php
appModelsEmployee.php
Now change your function to :
I believe this question is regarding phpmyadmin and not the relationships in laravel.
When creating the table, is the migration using a forign key?
For example something similar to this on your emoloyee table
This is what creates a forign key in the database, rather than a relationship in laravel.