I have three models Customer, Task, Staffs. Now task is realted to customer and also staff is related to customer. But there is no relation between staff and task. How can i get all the three records from one ORM.
relationship
/*staff*/ /**have pivot table 'staff_customer' **/
public function customers(){
return $this->belongsToMany('Customer');
}
/*customer*/
public function staffs(){
return $this->belongsToMany('Staff');
}
public function tasks(){
return $this->hasMany('Task');
}
/*task*/ /** has cutomer_id in table*/
public function customer(){
return $this->belongsTo('Customer');
}
I have tasks filtered by dates already. I need its customers and the staffs related to those customers.
$tasks = Task::Where(...)->with('customer')->with('staffs')->get();
You want to base your query on
Customer
since this is the model containing both relations. I believe something like this would work:Edit
I believe this should be possible as well:
Read the docs here: