Support the ongoing development of Laravel.io →
Eloquent Architecture
Last updated 1 year ago.
0

So here is what I did to get it work, but if anyone knows better solution please advise!

// User model: overriden getAttribute method

public function getAttribute($key)
{
	if ($key == 'reviews')
	{
		if ( ! array_key_exists($key, $this->getRelations()))
		{
			$this->load($key);
		} 

		$this->getRelation($key)->setParent($this->getKey());
	}

	return parent::getAttribute($key);
}
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.