In my model I have the following two functions:
public function Children()
{
return $this->hasMany(Menu::class, 'parent_menu_id', 'id');
}
public function ActiveChildren()
{
$securityLevel = Auth()->User()->security_level_id;
$activeChildren = Menu::Children()->where('active_', TRUE)->where('security_level_id', $securityLevel);
return $activeChildren;
}
Children() returns a list of all Menu items where their parent_menu_id matches the id of this record. This is used in Nova for setup purposes.
With ActiveChildren() I am trying to create a filtered list of items for the actual menu where active_ = TRUE and security_level_id = security level id of the current user.
But instead, ActiveChildren() returns all menu items instead of the filtered set. ActiveChildren populates an array in the following static function:
public static function Tree()
{
return static::with(implode('.', array_fill(0, 4, 'ActiveChildren')))->where('menu_type', '=', 'PRT')->get();
}
That is then loaded via the AppServiceProvider whenever the menu is included in a blade file:
public function boot()
{
view()->composer('desktop.menu.parent', function ($view) {
$items = Menu::Tree();
$view->withItems($items);
});
}
All this works fine, just the menu items are not filtered, any ideas?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire