【发布时间】:2016-04-18 05:02:00
【问题描述】:
我有两个名为users 和profiles 的表。在users 表中有一个名为id 的列,在profiles 表中有一个名为userID 的列。现在我想要@987654327 @table增加id然后userID分别自动填满。
如果有人创建配置文件,则 userID 列会根据登录 users 表 id 自动填充。我该怎么做?
用户模型:
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $table ="users";
protected $fillable = [
'userName', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function profileHave(){
return $this->hasOne('App\Profile','userID');
}
}
个人资料模型:
class Profile extends Model
{
//
protected $table = "profiles";
public $fillable = ["userID","firstName","lastName","middleName","DOB","gender","featuredProfile","email","phone","summary","profilePic"];
public function userHave(){
return $this->belongsTo('App\User','userID');
}
}
但是当我添加一个用户的配置文件时,profiles 表中的userID 列是空白的。但它应该根据users 表的登录 ID 填写。
顺便说一句,我是 Laravel 的新手。 谢谢。
【问题讨论】:
标签: php mysql sql-server laravel laravel-5.2