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

Filter Sorter Bundle Laravel Package

bartlomiejbeta/filter-sorter-bundle

View on GitHub
Deep Wiki
Context7

FilterSorterBundle

This Symfony bundle aims to provide structurized filtering and sorting with usage of the specification pattern (see doctrine-specification). It was design to use in the api applications but it could be also used with standard web apps.

Provides feature like:
  • FilterQueryManager - it collects all filter services and gives you queryBuilder with applied specifications.
  • FilterParamConverter - provide filter object by the data in query string
  • SortParamConverter - provide sort object by the data in query string

Build Status

Installation

1. Install via composer:
composer require bartlomiejbeta/filter-sorter-bundle
2. Register bundle in AppKernel:
public function registerBundles()
{
    $bundles = array(
        // ...
        new BartB\FilterSorterBundle\FilterSorterBundle(),
    );
}

Usage

I assume that you already have entities, and so one.

1. Change parent of the entities to AbstractEntitySpecificationAwareRepository:

example:

class CarRepository extends AbstractEntitySpecificationAwareRepository
{
}
2. Add specifications (example)
3. Add Collection filter (example)
4. Add Sort Enum (example)
5. Build and register your first service adapter (adapter example, register adapter example)
5. Run (standard, api with paramConverters)
$carCollectionFilter = (new CarCollectionFilter())->setGearboxType('automatic');

$carSorter     = new CarSort(CarSort::FUEL_TYPE);
$sortDirection = new SortDirectionType(SortDirectionType::DESC);
		
/** @var FilterQueryManager $filterQueryManager */
$filterQueryManager = $this->filterQueryManager;
$carRepository      = $this->repostioryCar;
$sort 	            = new Sort($sortDirection, $carSorter);
$limit              = new Limit(1);

$basicRepositoryDTO = new BasicRepositoryDTO($carRepository);
$queryAttributesDTO = new QueryAttributesDTO($carCollectionFilter, $sort, $limit);

$queryBuilder = $filterQueryManager->getQueryBuilder($basicRepositoryDTO, $queryAttributesDTO);
$query        = $queryBuilder->getQuery();
$result       = $query->execute();

TODO: Upgrade example to symfony 3.4 Also I prepared full stand alone example

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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle