Skip to content

Resource badge should be visible when including a resource via the MenuItem #4602

@vesper8

Description

@vesper8
  • Laravel Version: 8.83.19
  • Nova Version: 4.12.6
  • PHP Version: 8.1.6

Description:

I've had to resort to building out the menu fully custom because I wanted more control over the ordering of groups. My menu is now fully working. But as a result of doing this, I've lost all my badges that I already setup inside each resource file using this syntax:


    public function menu(Request $request)
    {
        return parent::menu($request)->withBadge(function () {
            return 123;
        });
    }    

When resolving a resource like this:


MenuItem::resource(App\Nova\Resources\User::class)

If that Nova Resource already has a badge setup using the above menu syntax, I feel like this badge should be displayed.

I know that I can use ->withBadge(fn() => 13, 'danger') but this means moving a huge chunk of code from the individual resource files (where this logic belongs IMO) to my "menu generation" class. That's a whole lot of code because currently my badge logic references itself and uses caching such as this:

    public function menu(Request $request)
    {
        return parent::menu($request)->withBadge(function () {
            $cacheKey = sprintf('users-badge-count');

            return \Cache::tags(['nova-badges'])->has($cacheKey) ? \Cache::tags(['nova-badges'])->get($cacheKey) : \Cache::tags(['nova-badges'])->remember($cacheKey, now()->add('1 hour'), function () {
                return (new self::$model)->count();
            });
        });
    }

So it would be great if you could simply use the badge that is already setup in the resource class. I consider this more of a bug than a feature request.

Many thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions