我有两个表——users和user_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,
]);
}
如何获取user_id?附言:我为我的英语感到抱歉。
执行此操作$user=新用户
$user->thing1=12;$user->thing2=32;$user->save();
现在,一旦你调用了保存方法,你就可以通过获得id
$user->id;
记住!只有在调用save方法后,它才会起作用。
还记得用你的数据替换我的数据。
有关更多信息和解释,请参阅此处:https://laravel.com/docs/5.2/eloquent#basic-插入
祝你好运!