Weave 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.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager