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

By adding some function I came a little further. Unfortunately I still can't use the Model::has and Model::whereHas functions, which are quite important.

public function getRestrictedToAttribute()
{
	if(!is_null($this->restricted_to_id) && $this->restricted_to_id !== '')
	{
		$classToType = '';
		list(, $classToType) = explode('\\', $this->restricted_to_type);
		$classToType = snake_case(str_plural($classToType));

		return $this->relations['restricted_to'] = call_user_func_array([$this, 'restricted_to_' . $classToType], [])->getResults();
	}

}


public function restricted_to_materials()
{
	return $this->morphToMany('App\Materials', 'restricted_to', 'options', 'id', 'restricted_to_id');
}

public function restricted_to_material_categories()
{
	return $this->morphToMany('App\MaterialCategories', 'restricted_to', 'options', 'id', 'restricted_to_id');
}

Does someone have an idea?

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.