4 years ago

Setting Eloquent relations to protected

Posted 4 years ago by tag

I am trying to properly hide away the Eloquent signature of a model such that I can give it a proper set of interfaces, and one step I've taken is to set the relations to protected.

However, that causes a problem whereby whereHas(....) no longer works.

Given this query from the Member model:

    public function getClan(SectionInterface $section)
        return $this->clans()->whereHas('teams', function($q) use ($section) {
            $q->where('section_id', $section->getID());

If the teams() relation method on the Clan model is set to protected, this query can't work (which is to be expected I suppose).

My question is, does anyone have a recommendation for allowing these kinds of relation builder queries without actually exposing the relations publicly?

Please sign in or create an account to participate in this conversation.