ofMany based on a relation
I have a model "Lead" this model has an one to many relationship with a model "ActivityLead" and there is an one to one polymorphic table with "ActivityDetail" which contain extra information about the activity.
The "ActivityDetail" has these 2 columns "proposed_start_at" which is a date and a boolean column "is_completed".
I want with Laravel's ofMany method to get the upcoming incomplete activity in which I need to sort the proposed_start_at MIN and check if is_complete is false.
But how to do that since these information are on the 3rd model "ActivityDetail"?
The below wont work because "proposed_start_at" is not on the ActivityLead model.
Thanks.
/**
* Get the upcoming incomplete activity.
*
* @return HasOne
*/
public function upcomingIncompleteActivity(): HasOne
{
return $this->hasOne(ActivityLead::class)->ofMany([
'proposed_start_at' => 'min'
], function ($query) {
$query->whereHas('details', function (Builder $query) {
$query->where('is_completed', false);
});
});
}
Please or to participate in this conversation.