Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Crud Bundle Laravel Package

araise/crud-bundle

View on GitHub
Deep Wiki
Context7

Filters

Filters can be defined inside a Definition.

Default behaviour

Whenever you create a Definition it will create some filters for you. Out of the box the filters are defined by the properties of the Entity. If this behaviour does not fit your needs properly, you can always override the configureFilters()-method to change the labels, create custom filters or remove auto-generated ones. You can also allow the user to select some predefined filters.

â„šī¸ Note that you don't necessarily have to call parent::configureFilters($table) when you override the configureFilters-method. But you will only get the auto-generated filters if you do. Having them generated by the TableBundle will improve the readability of your code. That's why we highly recommend using it.

How to override filter label

The bundle tries to detect labels automatically, you can however override the generated labels very easily:

public function configureFilters(Table $table)
{
    parent::configureFilters($table);
    $table->getFilterExtension()
        ->overrideFilterName('lastname', 'By lastname');
    // overrideFilterName(acronym, new label value)
}

Result

This image shows the resulting user interface of the code above

How to add a custom filter

The bundle tries to detect labels automatically, you can however override the generated labels easily:

public function configureFilters(Table $table)
{
    parent::configureFilters($table);
    $table->getFilterExtension()
        ->addFilterType('age', 'Age', NumberFilterType::class, [
            FilterType::OPT_COLUMN => (self::getQueryAlias() . '.age')
        ]);
    // addFilterType(acronym, label, FilterType, options)
}

Result

This image shows the resulting user interface of the code above

How to remove an unwanted filter

You can also remove filters that have been auto-generated:

public function configureFilters(Table $table)
{
    parent::configureFilters($table);
    $table->getFilterExtension()
        ->removeFilter('birthday');
    // removeFilter(acronym)
}

Result

This image shows the resulting user interface of the code above

How to predefine often used filters

Sometimes you have filters or a set of filters that you use pretty often. Instead of always clicking them together in the UI, you can predefine them via code and make them available to all users:

(For instance we often search for users with blonde hair, a height of at least 180cm and only persons that identify as women)

public function configureFilters(Table $table)
{
    parent::configureFilters($table);
    $table->getFilterExtension()
        ->predefineFilter('custom_query', 'hair', TextFilterType::CRITERIA_EQUAL, HairColorEnum::BLONDE)
        ->and('height', NumberFilterType::CRITERIA_BIGGER_THAN, 180)
        ->and('gender', TextFilterType::CRITERIA_EQUAL, GenderEnum::WOMAN)
    ->end();
    // predefineFilter(acronym, label, operator, value)
}

It is now possible to open http://[domain].[tld]/[your-site-with-the-table]?[table-identifier]_filter_predefined=custom_query and the declared filters will be applied.


🔗 For more infos on filters or the TableBundle, take a look into the documentation.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware