New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

rafflesargentina/l5-filterable-sortable

A trait for filtering and sorting Query Builder results, based on Laracasts/Dedicated-Query-String-Filtering
244 3

Larablocks Analysis

rafflesargentina/l5-filterable-sortable works with Laravel 6 (latest release v2.6.0, Jun 24, 2020), which reached end of life on Sep 6, 2022: no more fixes, even for security.

Laravel 5 in earlier releases.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 6, past end of life since Sep 6, 2022
  • No release in the last 12 months (last: Jun 24, 2020)
  • 0 downloads a month (needs 10,000)
  • 3 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Jun 24, 2020.
  • No releases in the last 12 months.
  • First released: Dec 27, 2017.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 1, 2026.

Install
composer require rafflesargentina/l5-filterable-sortable
Latest Version:v2.6.0
PHP:>=7.2.0
Laravel:6
Older releases:5
License:MIT
Last Updated:Jun 24, 2020
Links: GitHub  ·  Packagist
Maintainer: rafflesargentina

l5-filterable-sortable

Latest Version on Packagist Software License Build Status Total Downloads

A trait for filtering and sorting Query Builder strings, based on Laracasts/Dedicated-Query-String-Filtering.

Install

Via Composer

$ composer require rafflesargentina/l5-filterable-sortable

Usage

Add FilterableSortableTrait to your Eloquent model so you can make use of filter() and sorter() scopes. Both apply clauses to the Builder intance that you must define as functions in separate classes. So you must add $filters and $sorters properties to your model to set those classes.

Example:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

use RafflesArgentina\FilterableSortable\FilterableSortableTrait;

use App\Filters\ArticleFilters;
use App\Sorters\ArticleSorters;

class Article extends Model
{
    use FilterableSortableTrait;

    public $filters = ArticleFilters::class;

    public $sorters = ArticleSorters::class;

    // ...
}

QueryFilters

Create a class that extends QueryFilters and define methods named after each request data you want to use as a chained query filter. You can employ any logic inside functions, as long as they return a Builder instance.

Example:

<?php

namespace App\Filters;

use RafflesArgentina\FilterableSortable\QueryFilters;

class ArticleFilters extends QueryFilters
{
    public function title($query)
    {
        return $this->builder->where('title', 'LIKE', '%'.$query.'%');
    }

    public function author($query)
    {
        return $this->builder->where('user_id', $query);
    }

    public function category_id($query)
    {
        return $this->builder->where('category_id', $query);
    }
}

You can also access the class method getAppliedFilters() statically, to get an array of the filters applied from request.

QuerySorters

Create a class that extends QuerySorters, and define public methods named after each request data you want to use as a chained query sorter. You can employ any logic inside functions, as long as they return a Builder instance. Default order and default orderBy must be set through $defaultOrder and $defaultOrderBy static properties. Optionally you can define order and orderBy keys through $orderKey and $orderByKey static properties.

Example:

<?php

namespace App\Sorters;

use RafflesArgentina\FilterableSortable\QuerySorters;

class ArticleSorters extends QuerySorters
{
    // These properties are optional:

    protected static $orderKey = 'orden'; // Fallback value is 'order'

    protected static $orderByKey = 'ordenarPor'; // Fallback value is 'orderBy'

    // And there are mandatory:

    protected static $defaultOrder = 'asc';

    protected static $defaultOrderBy = 'title';

    public function title()
    {
        return $this->builder->orderBy('title', $this->order());
    }

    public function published_at()
    {
        return $this->builder->orderBy('updated_at', $this->order())
                             ->orderBy('title', $this->order());
    }

}

Also you can access these static class methods to get sorter class protected data: getOrderKey(), getOrderByKey(), getDefaultOrder(), getDefaultOrderBy(). Use getAppliedSorters() to get applied sorters from request. Or listOrderByKeys() to populate a dropdown selector.

You can get filtered and sortered records from your model from controller or anywhere you want like this:

// ...

$items = Article::filter()->sorter()->paginate();

// ...

That's it :)

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email mario@raffles.com.ar instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Alternatives to rafflesargentina/l5-filterable-sortable

tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

5,823,991 1,760
jerome/filterable

Streamline dynamic Eloquent query filtering with seamless API request integratio...

69,571 194
mehradsadeghi/laravel-filter-querystring

Filter your queries based on url query string parameters like a breeze.

149,902 167
innoboxrr/search-surge

Filtrado, ordenamiento y paginacion declarativa para modelos Eloquent. Auto-desc...

5,307 0
kalimeromk/filterable

A Laravel package that simplifies dynamic filtering and searching across models...

3,388 5

Version History

Version Released PHP Laravel License
v2.6.0 >=7.2.0 6.* MIT
v1.8.0 >=7.1.3 5.8.* MIT
v1.7.0 >=7.1.3 5.7.* MIT
v1.6.1 >=7.1.3 5.6.* MIT
v1.6.0 >=7.1.3 5.6.* MIT