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?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community