我想在注册后插入userbio
这里是我的注册RegisterController
protected function create(array $data)
{
$databio = new ModelBio();
$maxbio = $databio->getMaxbioId();
// die( $maxbio );
return User::create([
'username' => $data['username'],
'email' => $data['email'],
'biodataId' => $maxbio,
'password' => bcrypt($data['password']),
]);
return Biodata::create([
'biodataId' => $maxbio,
'fullname' => $data['fullname']
]);
}
它为Users
创建新记录。但是,有一个问题我无法插入usersbio
,我找不到任何错误消息。顺便说一句RegisterController
来自laravel auth。这是我的Biodata
class Biodata extends Model
{
//
protected $primaryKey = 'biodataId';
protected $table = "usersbio";
public $incrementing = false;
protected $fillable = [
'biodataId','address','fullname','remarks'
];
static function getMaxbioId(){
$max = Biodata::max('biodataId');
if($max == ""){
return "BIO-0001";
}else{
$number = substr($max, 4);
return 'BIO-' . sprintf('%04d', intval($number) + 1);
}
}
}
我该如何解决?提前谢谢
答案 0 :(得分:1)
创建用户时不要写return
。它实际上从那里返回,并且不会执行该函数的其他代码。
protected function create(array $data)
{
$databio = new ModelBio();
$maxbio = $databio->getMaxbioId();
// die( $maxbio );
User::create([ // Removed `return` from here
'username' => $data['username'],
'email' => $data['email'],
'biodataId' => $maxbio,
'password' => bcrypt($data['password']),
]);
return Biodata::create([
'biodataId' => $maxbio,
'fullname' => $data['fullname']
]);
}