All Projects → devmakerlab → laravel-filters

devmakerlab / laravel-filters

Licence: other
Need some filters? This package is based on the Repository Design Pattern to let you create specific queries easily.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-filters

Exopite-Multifilter-Multi-Sorter-WordPress-Plugin
Display and/or sort/filter any page or post types by multiple taxonomies or terms (like post by categories and/or tags) with AJAX. Exopite multifilter, multi-sortable, multi selectable, multi filterable sortable Wordpress Plugin.
Stars: ✭ 18 (-5.26%)
Mutual labels:  filters
dumb delegator
Delegator and SimpleDelegator in Ruby's stdlib are useful, but they pull in most of Kernel. This is not appropriate for many uses; for instance, delegation to Rails models.
Stars: ✭ 62 (+226.32%)
Mutual labels:  design-patterns
riblet-sample
A sample to represent Uber Riblets design pattern using Swift.
Stars: ✭ 42 (+121.05%)
Mutual labels:  design-patterns
ezyfox
Java library supports for reflection, generic, annotations parsing, bean management and object binding
Stars: ✭ 14 (-26.32%)
Mutual labels:  design-patterns
TestableDesignExample
Sample App to learn a testable design (Smalltalk flavored MVC)
Stars: ✭ 80 (+321.05%)
Mutual labels:  design-patterns
Kodkod
https://github.com/alirizaadiyahsi/Nucleus Web API layered architecture startup template with ASP.NET Core 2.1, EF Core 2.1 and Vue Client
Stars: ✭ 45 (+136.84%)
Mutual labels:  design-patterns
CoreImagePython
Write and test Core Image filters, kernels, and geometric transformations in Python.
Stars: ✭ 43 (+126.32%)
Mutual labels:  filters
java-design-patterns-web
Java Design Patterns website at https://java-design-patterns.com
Stars: ✭ 81 (+326.32%)
Mutual labels:  design-patterns
DataStructures Algorithms Java
Collection of data structures and algorithms challenges that I've solved. 💤
Stars: ✭ 12 (-36.84%)
Mutual labels:  design-patterns
design-patterns
👨🏻‍💻 Swoole微课程-PHP设计模式相关代码
Stars: ✭ 51 (+168.42%)
Mutual labels:  design-patterns
vala-design-patterns-for-humans
A Vala version of "Design Patterns for Humans"
Stars: ✭ 15 (-21.05%)
Mutual labels:  design-patterns
DotNETCarRental
Daily car rental simulation with ASP.NET.
Stars: ✭ 13 (-31.58%)
Mutual labels:  design-patterns
adhesion-rs
D-inspired contract programming in Rust using macros
Stars: ✭ 49 (+157.89%)
Mutual labels:  design-patterns
mvc-tree
🌳 A chronological visualization of the family of MVC patterns.
Stars: ✭ 40 (+110.53%)
Mutual labels:  design-patterns
data-algorithms-with-spark
O'Reilly Book: [Data Algorithms with Spark] by Mahmoud Parsian
Stars: ✭ 34 (+78.95%)
Mutual labels:  design-patterns
BioBalanceDetector
Bio Balance Detector's products aim to show the weak electromagnetic fields around every living being (including plants, animals and humans) and display it in a heat-map like hyper-spectral image.
Stars: ✭ 18 (-5.26%)
Mutual labels:  filters
chuxiuhong-rust-patterns-zh
Rust设计模式中文翻译
Stars: ✭ 36 (+89.47%)
Mutual labels:  design-patterns
CSharpDesignPatterns
Examples of design patterns, using C# code.
Stars: ✭ 84 (+342.11%)
Mutual labels:  design-patterns
patterns
📰 A collection of UI / UX patterns for different types of applications
Stars: ✭ 67 (+252.63%)
Mutual labels:  design-patterns
design-patterns-java
📗 Classic OOP Design Patterns from GoF, implemented in Java.
Stars: ✭ 25 (+31.58%)
Mutual labels:  design-patterns

Build Status Code Coverage Latest Version on Packagist

DevMakerLab/Laravel-Filters

Need some filters? This package is based on the Repository Design Pattern to let you create specific queries easily.

Installation

⚠️ Requires >= PHP 7.4 ⚠️

composer require devmakerlab/laravel-filters

Usage

This package offers an abstract class AbstractFilterableRepository which needs to be extended to implement the features of this package.

PeopleService.php

<?php
    ...
    $peopleRepository = new PeopleRepository($databaseManager);
    
    $people = $peopleRepository
            ->addFilter(OldPeopleFilter::class)
            ->get(['age' => 60]);

OldPeopleFilter.php

<?php

declare(strict_types=1);

use Illuminate\Database\Query\Builder;
use DevMakerLab\LaravelFilters\AbstractFilter;

class OldPeopleFilter extends AbstractFilter
{
    public int $age;

    public function apply(Builder $queryBuilder): void
    {
        $queryBuilder->where('age', '>=', $this->age);
    }
}

PeopleRepository.php

<?php

declare(strict_types=1);

use DevMakerLab\LaravelFilters\AbstractFilterableRepository;

class PeopleRepository extends AbstractFilterableRepository
{
    private DatabaseManager $databaseManager;

    public function __construct(DatabaseManager $databaseManager)
    {
        $this->databaseManager = $databaseManager;
    }

    public function get(array $args): array
    {
        $queryBuilder = $this->databaseManager->table('people')
            ->select(['firstname', 'lastname', 'age', 'gender']);

        $this->applyFilters($queryBuilder, $args);

        $people = $queryBuilder->get();

        return $this->transform($people);
    }

    public function transform(Collection $people): array
    {
        $people->transform(function ($person) {
            return [
                'name' => sprintf('%s %s', $person->lastname, $person->firstname),
                'age' => $person->age,
                'gender' => $person->gender,
            ];
        });

        return $people->toArray();
    }
}

Example

Usage Example of DevMakerLab/Laravel-Filters package.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].