I am having problem in getting the hasmany
relationship data in Laravel eloquent.
AModel hasmany BModel AModel hasmany CModel
AModel has function:
Public function bmodels(){
return hasMany('BModel');
}
Public function cmodels(){
return hasMany('CModel');
}
BModel has function:
Public function bmodels(){
return belongsTo('AModel', amodel_id);
}
CModel has function:
Public function cmodels(){
return belongsTo('AModel',amodel_id);
}
Now i am trying to get it like this
$amodels = AModel::with('bmodels','cmodels')
->where('status_id','2200')
->whereIn('eventstatus_id',['1','2'])
->get();
and now i want to test this in the for loop.
foreach($amodels as $amodel){
$bmodels = $model->bmodels();
if ($amodel && $amodel->end < Carbon::now()){
foreach ($bmodels as $bmodel){
$cmodels = $amodel->cmodels();
foreach($cmodels as $cmodel){
if ($bmodel->id !== $cmodel->reservation_id || $cmodel->reservation_id != null ){
array_push($reservation_needed_to_enter,$bmodel->id);
}
}
}
}
}