1
我需要在同一時間創建兩個用戶。這是我在AuthController中的代碼:Laravel多創建用戶
protected function create(array $data) {
$profile = New \App\ClientDetail();
$profile->s_firstname = $data['s_firstname'];
$profile->s_surname = $data['s_surname'];
$profile->p_firstname = $data['p_firstname'];
$profile->p_surname = $data['p_surname'];
$profile->s_mobile_number = $data['s_mob_number'];
$profile->s_home_number = $data['s_home_number'];
$profile->p_mobile_number = $data['p_mob_number'];
$profile->p_home_number = $data['p_home_number'];
[...all the form information fields]
$profile->save();
/*FIRST USER TO CREATE*/
if($data['s_email']) {
$user = User::create([
'detail_id' => $profile->id,
'email' => $data['s_email'],
'password' => bcrypt('secret'),
]);
$user->attachRole($student);
}
/*SECOND USER TO CREATE*/
if($data['p_email']) {
$user = User::create([
'detail_id' => $profile->id,
'email' => $data['p_email'],
'password' => bcrypt('secret'),
]);
$user->attachRole($parent);
}
return $user;
}
問題是令牌只存儲在最後創建的用戶中。在mysql數據庫中,對於第一個用戶,列remember_token
是null
。
如何創建兩個不同的標記?
如果您有另一個同時創建兩個用戶的好主意,請告訴我。
感謝