Support the ongoing development of Laravel.io →
posted 5 months ago
Nova

In Laravel 10 / nova 4.27 app I added custom menu with products items :

            MenuSection::make('Products', [
                MenuItem::make('Products', '/resources/products'),
                MenuItem::make('Create Product', '/resources/products/new'),
            ])->collapsable(),

Also Product resource has custom filters :

/**
 * Get the filters available for the resource.
 *
 * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
 *
 * @return array
 */
public function filters(NovaRequest $request)
{
    return [new ProductByStatus];
}

where ProductByStatus defined app/Nova/Filters/ProductByStatus.php:

class ProductByStatus extends Filter
{
    public $name = 'By status';

    public $component = 'select-filter';

    public function apply(NovaRequest $request, $query, $value)
    {
        return $query->where('status', $value);
    }

    public function options(NovaRequest $request)
    {
        return ProductStatusEnum::getStatusSelectionItems(labelAsKey: true);
    }

and enum file app/Enums/ProductStatusEnum.php:

enum ProductStatusEnum: string
{
    case DRAFT = 'D';
    case PENDING_REVIEW = 'P';
    case ACTIVE = 'A';
    case INACTIVE = 'I';

    public static function getStatusSelectionItems(bool $labelAsKey = false): array
    {
        $statusSelectionItems = [
            self::DRAFT->value => 'Draft', //  D => Draft
            self::PENDING_REVIEW->value => 'Pending Review',  // P=>Pending Review
            self::ACTIVE->value => 'Active',  // A-Active
            self::INACTIVE->value => 'Inactive',  // I-Inactive
        ];
        $resArray = [];
        foreach ($statusSelectionItems as $key => $label) {
            if($labelAsKey) {
                $resArray[$label] = $key;
            } else {
                $resArray[$key] = $label;
            }
        }

        return $resArray;
    }

Next I want to create a menu item with only Active product, but when I run Product filter with Status = 'Active'

I see such url in my browser :

http://local-nova-products.com/nova/resources/products?products_page=1&products_filter=W3siQXBwXFxOb3ZhXFxGaWx0ZXJzXFxQcm9kdWN0QnlCcmFuZCI6IiJ9LHsiQXBwXFxOb3ZhXFxGaWx0ZXJzXFxQcm9kdWN0QnlTdGF0dXMiOiJEIn0seyJBcHBcXE5vdmFcXEZpbHRlcnNcXFByb2R1Y3RCeVB1Ymxpc2hlZEF0RmlsdGVyIjoiIn1d

How this products_filter created for me to run such filter manually ?

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.

© 2025 Laravel.io - All rights reserved.