We get one relationship. Now we set conditions on relationship to get status and check one by one with each case. After getting the status type, the value of status type will pass to another relationship. how can we do this? Here is an example below.
/////// Model function use for relationship//////
public function Name($statusType){
$value='';
switch ($statusType){
case 0:
$value= $this->belongsTo(/////code//////);
break;
case 1:
$value= $this->belongsTo(/////code//////);
break;
case 6:
$value= $this->belongsTo(/////code//////);
break;
case 2:
$value= $this->belongsTo(/////code//////);
break;
case 3:
$value= $this->belongsTo(/////code//////);
break;
case 4:
$value= $this->belongsTo(/////code//////);
break;
}
return $value;
}
It's my controller Function
$Variable = ModelName::where('id', $id])->with(['RelationShipName' => function ($query) use ($startDate) {
$query->whereDate('date', '>=', $startDate)->orderBy('date', 'DESC');
},'RelationShipName.anotherRelationShipName'])->get();
Example
$Variable = ModelName::where('id', $id])->with(['RelationShipName' => function ($query) use ($startDate) {
////how to get statusType and pass argument///
$query->whereDate('date', '>=', $startDate)->orderBy('date', 'DESC');
},'RelationShipName.anotherRelationShipName(argument)'])->get();