vendredi 27 mai 2016

laravel 5.1 : how can i get nested relation from model?

I have a question about laravel model relations and use them in eloquent class . my question is this :

I have a model like this :

class TransferFormsContent extends Model
{

 public function transferForm()
    {
        return $this->belongsTo('App\TransfersForms','form_id');
    }
}

and in transferForm i have other side for this relation like this :

  public function transferFormsContent()
{
    return $this->hasMany('App\TransferFormsContent', 'form_id', 'id');
}

also in transferForm i have another relation with employee like this :

class TransfersForms extends Model
{
     public function employee()
        {
            return $this->belongsTo('App\User','employee_id');
        }
}

now if I want get a record from "TransferFormsContent" with its "transferForm " provided its with employee. how can i do this?

i now if i want get "TransferFormsContent" with only "transferForm " i can use from this :

 $row = $this->model
            ->with('transferForm'); 

but how about if i want transferForm also be with its employee?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire