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

Overview

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.

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();
    }
}

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);
    }
}

Example

Usage Example of DevMakerLab/Laravel-Filters package.

You might also like...
Laravel basic Functions, eloquent cruds, query filters, constants

Emmanuelpcg laravel-basics Description Package with basic starter features for Laravel. Install If Builder Constants Install composer require emmanuel

Shell script for Git module deployment with include/exclude filters.

Deploy multiple Git repositories in an unique folder modgit is a shell script for deploying multiple Git repositories in root folder of any project, w

A collection of easy-to-use filters with clause conditions to Filament
A collection of easy-to-use filters with clause conditions to Filament

Filament Advanced Filter A collection of easy-to-use filters with clause conditions to Filament Installation Install the package via composer (require

Create and manage A Domain Driven Design (DDD) in your Laravel app, simply and efficiently.

Create and manage A Domain Driven Design (DDD) in your Laravel app, simply and efficiently.

Create a downloads list - quick and easy. With categories and mobile friendly design
Create a downloads list - quick and easy. With categories and mobile friendly design

Simple downloads list plugin for wordpress Create a downloads list - quick and easy. With categories and mobile friendly design What is Simple downloa

Worlds (soon to be) most advanced Anime site! Featuring Administration features and everything you need for users and yourself. The successor of aniZero.

/**********************************************************************\ | _____ H33Tx & xHENAI __ 31.01.2022| |

The missing laravel helper that allows you to inspect your eloquent queries with it's bind parameters

Laravel Query Inspector The missing laravel helper that allows you to ispect your eloquent queries with it's bind parameters Motivations Let's say you

Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries
Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries, this package will contain all advanced SQL

Let's base your Laravel project with PROS style

Purpose This library is for convenient methods that use to register code base for Laravel project Target We aimed to reduce complexity for real projec

Releases(v1.3)
Owner
DevMakerLab
DevMakerLab
A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly.

PHPColors A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly. Requirements PHPColo

Arlo Carreon 423 Dec 20, 2022
Auto-generated Interface and Repository file via Repository pattern in Laravel

Auto-generated Repository Pattern in Laravel A repository is a separation between a domain and a persistent layer. The repository provides a collectio

Ngo Dinh Cuong 11 Aug 15, 2022
Laravel Design Pattern Generator (api generator)

Laravel Design Pattern Generator (api generator) you can create your restful api easily by using this library and you can filter, sort and include elo

HusseinAlaa 2 Sep 25, 2022
Fast and simple implementation of a REST API based on the Laravel Framework, Repository Pattern, Eloquent Resources, Translatability, and Swagger.

Laravel Headless What about? This allows a fast and simple implementation of a REST API based on the Laravel Framework, Repository Pattern, Eloquent R

Julien SCHMITT 6 Dec 30, 2022
Database Repository / PHP Repository / Laravel Repository

Database Repository / PHP Repository / Laravel Repository Installation Use following command to add this package to composer development requirement.

Bakery 6 Dec 21, 2022
A package to implement repository pattern for laravel models

Laravel Model UUID A simple package to use Repository Pattern approach for laravel models . Repository pattern Repositories are classes or components

null 26 Dec 21, 2022
States allows you to create PHP classes following the State Pattern in PHP.

States allows you to create PHP classes following the State Pattern in PHP. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and this improve maintainability and workflows writing.

Teknoo Software 10 Nov 20, 2022
A plugin for Blessing Skin Server that can let you display Google Ads with Google AdSense in the website.

A plugin for Blessing Skin Server that can let you display Google Ads with Google AdSense in the website.

Big_Cake 2 Jan 25, 2022
Repository Pattern implementation for Laravel

This is a Simple Repository Pattern implementation for Laravel Projects and an easily way to build Eloquent queries from API requests.

Ephraïm SEDDOR 1 Nov 22, 2021
a Laravel package help you to execute more effective databases queries.

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimizing sql queries, this package will contain all advanced sq

karam mustafa 9 Jul 26, 2022