I'm trying to load a hasone relation on a loaded hasmany relation.
Basically, I have loaded my completion logs, but would like to also load the pool_section model relation for each of the loaded completion log records.
$appointments = Appointment::primaryAppointments()->ofReportingPeriod($reportingPeriod->id)->take(5)->get();
$appointments = $appointments->load('profile', 'department')->load(['completion_logs' => function ($query) use ($reportingPeriod) {
$query->where('reporting_period_id', $reportingPeriod->id)->whereNotNull('pool_section_id')->orderBy('pool_section_id');
}]);
Trying to load the pool_section relation onto the loaded completion logs from above:
class PoolSectionCompletion extends Model
public function pool_section()
{
return $this->belongsTo('App\Models\PoolSection', 'pool_section_id', 'id');
}
class Appointment extends Model
public function completion_logs()
{
return $this->hasManyThrough('App\Models\PoolSectionCompletion', 'App\Models\Profile', 'id', 'profile_id', 'profile_id', 'id');
}
I'm trying to load the select completion logs an then load the pool_section relation based on the id in order to get the pool_section data for each of the loaded completion logs. Any help is appreciated.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire