【发布时间】:2014-06-03 02:57:12
【问题描述】:
如何用关系保存新用户?
用户模型:
public function profile(){
return $this->hasOne('Profile','id');
}
轮廓模型:
protected $table = 'users_personal';
public function user(){
return $this->belongsTo('User','id');
}
主要功能:
$u = new User;
$u->username = $i['username'];
$u->email = $i['mail'];
$u->password = Hash::make( $i['password'] );
$u->type = 0;
$u->profile->id = $u->id;
$u->profile->name = $i['name'];
$u->profile->surname = $i['surname'];
$u->profile->address = $i['address'];
$u->profile->number = $i['strnum'];
$u->profile->city = $i['city'];
$u->profile->ptt = $i['ptt'];
$u->profile->mobile = $i['mobile'];
$u->profile->birthday = $i['year'].'-'.$i['mob'].'-'.$i['dob'];
$u->profile->newsletter = $i['news'];
$u->push();
如果我这样做,我会收到错误:间接修改重载属性 User::$profile 无效
创建新用户时如何保存用户配置文件?
【问题讨论】: