LaravelPackages.net
Acme Inc.
Toggle sidebar
tsfcorp/lister

Listing library for Laravel

4.887
3
v2.0.3
About tsfcorp/lister

tsfcorp/lister is a Laravel package for listing library for laravel. It currently has 3 GitHub stars and 4.887 downloads on Packagist (latest version v2.0.3). Install it with composer require tsfcorp/lister. Discover more Laravel packages by tsfcorp or browse all Laravel packages to compare alternatives.

Last updated

Listing library for Laravel

Makes it easy to list a resource

Upgrade from 1.x to 2.x

  • use TsfCorp\Lister\Facades\ListerFilter has been removed. use use TsfCorp\Lister\Filters\ListerFilter

Installation

Require this package in your composer.json and update composer. Run the following command:

composer require tsfcorp/lister

After updating composer, the service provider will automatically be registered and enabled, along with the facade, using Auto-Discovery

Next step is to run the artisan command to bring the config into your project

php artisan vendor:publish --provider="TsfCorp\Lister\ListerServiceProvider"

Update config/lister.php

Usage Instructions

Lister library can be added to your method signature, this way it will be resolved by DI container or it can be instatiated like this:

$lister = new Lister(request(), DB::connection());

Query settings must be specified in this format:

$query_settings = [
    'fields' => "users.*",

    'body' => "FROM users {filters}",

    'filters' => [
        "users.id IN (1,2,3)",
        "users.name LIKE '%{filter_name}%'",
    ],

    'sortables' => [
        'name' => 'asc',
    ],
    
    // optional, you can pass a model reference and the records returned 
    // will be of that type
    
    'model' => User:class,
];

$listing = $lister->make($query_settings)->get();
  • {filters} keyword must be specified in the body parameter, so it can be replaced with the conditions specified.
  • each item from filters param, will be added to WHERE clause. If the condition has a parameter specified in curly braces, we'll search for that parameter in the request and replace the parameter with value found.

If using remembered filters and also for query string cleanup, this is needed at the top of the method used:

if($redirect_url = $lister->getRedirectUrl()) return redirect($redirect_url);
Comments