我有一个包含6个字段的表格付款:date_payment, fk_student, number_seance, price, total
。
我还有一个名为学生的表,其中有5个字段:id, user_id, name, email, payment_id
。
我有一个表用户,其中包含3个字段:name, email, password
。
我在Laravel的人际关系中迷路
模型学生:
protected $fillable = ['user_id', 'name', 'email', 'payment_id'];
public function payments(){
return $this->hasMany('App\Payment', 'fk_student');
}
public function user()
{
return $this->belongsTo('App\User', 'id', 'user_id');
}
模型付款:
protected $fillable = ['date_payment', 'fk_student', 'number_seance', 'price', 'total'];
public function student(){
return $this->belongsTo('App\Stuent', 'fk_student');
}
public function user()
{
return $this->belongsTo('App\User', 'id', 'payment_id');
}
模型用户
public function student()
{
return $this->hasOne('App\Student', 'user_id', 'id');
}
public function payments()
{
return $this->hasOne('App\Student', 'payment_id', 'id');
}