javii-script / default-value-filterable
A Nova macro that streamlines setting a default value in addition to enabling filtering functionality on a field.
Installs: 4 580
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- laravel/nova: ^5.0
README
Nova Field Default Filter Macro is a custom macro for Laravel Nova that simplifies the process of setting default values and enabling filtering capabilities for fields.
Features
- Default Value for Filters: Easily set default values for fields when filters are applied.
- Customizable Filtering Logic: Define how the filtering is applied with custom callback functions.
- Seamless Integration: Designed specifically for Laravel Nova resources.
Screenshot
Requirements
To use this package, ensure your environment meets the following requirements:
- PHP:
^8.1
- Laravel Nova:
^5.0
Installation
Install the package via Composer:
composer require javii-script/default-value-filterable
Usage
The defaultFilterable macro makes it easy to define a default value for filters, enhancing the functionality of your Nova resources.
Basic Example
Text::make('Name') ->defaultFilterable(function () { return 'John Doe'; }),
In this example, the Name field will have a default filter value of John Doe.
Advanced Example with Custom Filtering Logic
Text::make('Name') ->defaultFilterable(function () { return 'John Doe'; }, function ($request, $query, $value, $attribute) { $query->where($attribute, 'LIKE', "{$value}%"); }),
In this example:
- Default Value: The Name field will default to John Doe when filtering.
- Custom Filtering: The filtering logic will apply a LIKE clause to match records where the Name starts with the filter value.
Contributing
Contributions are welcome! If you have ideas for improvements or find any issues, feel free to open an issue or submit a pull request.
License
This package is open-sourced software licensed under the MIT license.