dimanche 30 avril 2017

laravel 5.1 BelongsTo Reverse call

What i know:

$this->$parent->childs(); //we get childs data

what i want to know how:

$this->child->find($id)->parent(); //how to get childs parent without including model in controller | by just using eloquent

heres my sample code of employee and employeeDependent model:

trait EmployeeRelationships{

    public function dependents(){
        return $this->hasMany(\App\DB\EmployeeDependent\EmployeeDependent::class);
    }

}

trait EmployeeDependentRelationships{

    /**
     * @return mixed
     */
    public function employee(){
        return $this->belongsTo(\App\DB\Employee\Employee::class, 'employee_id');
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire