I am facing an issue in Polymorphic relations where I can not make whereHas to work. The relation code is working fine to return the related models, but need to apply where conditions to the relations of the models connected with the polymorphic relations?
My polymorphic relation is morph mapped by two models. eg: Events and Meetings both models have their own relations to store their assignees (Belongs to many) I need to apply where condition to assignees relation to fetch the required data, In my polymorphic relation, I got the data with assignees but not with the condition applied.
class MainEvant extends Model
{
public function eventheadable()
{
return $this->morphTo('eventhead', 'event_type_id', 'event_id')
->morphWith([ Events::class=>['assignee'],
Meeting::class=>['assignee'], ]);
}
}