I have two tables - users and user_attributes. During registration user I would like to not only enter the user in the user table but also create his attributes.
AuthController
protected function create(array $data)
{
User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
return UserAttribute::create([
'user_id' => $data['id'], // Undefined index: id
'lvl' => 0,
'exp' => 0,
'currency' => 500,
'premium_currency' => 5,
]);
}
How do I get user_id? PS: I'm sorry for my english.
Do this $user =new User;
$user->thing1 = 12; $user->thing2 =32; $user->save();
And now as soon as you have called the save method you can get the id by doing
$user->id;
Remember! It will only work after you have called the save method.
Also remember to replace my data with your data.
For further info and explanation see here: https://laravel.com/docs/5.2/eloquent#basic-inserts
Best of luck!