samedi 28 septembre 2019

I am lost in my relationships in Laravel?

I have a table payments with 6 fields: date_payment, fk_student, number_seance, price, total.

I also have a table named students with 5 fields: id, user_id, name, email, payment_id.

I have a table user with 3 fields: name, email, password.

I am lost in my relationships in Laravel

Model Student:

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');
}

Model Payment:

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');
    }

Model User

public function student()
{
    return $this->hasOne('App\Student', 'user_id', 'id');
}

public function payments()
{
    return $this->hasOne('App\Student', 'payment_id', 'id');
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire