Monday, March 27, 2023
HomePHPFilter and Search Eloquent Fashions with the Mannequin Filter Package deal

Filter and Search Eloquent Fashions with the Mannequin Filter Package deal

Laravel Mannequin Filter affords a easy strategy to filter and search eloquent fashions by array parameters and question strings.

This is a easy instance for instance precisely how this bundle works. Given the next filter, you’ll be able to generate with the offered make:filter command:

namespace AppModelsFilters;


use LacodixLaravelModelFilterFiltersDateFilter;


class CreatedAfterFilter extends DateFilter


public FilterMode $mode = FilterMode::GREATER_OR_EQUAL;


protected string $area = 'created_at';


You’ll be able to apply the CreatedAfterFilter on a mannequin like the next instance:

namespace AppModels;


use AppModelsFiltersCreatedAfterFilter;

use IlluminateDatabaseEloquentModel;

use LacodixLaravelModelFilterTraitsHasFilters;


class Submit extends Mannequin


use HasFilters;


protected array $filters = [




You’ll be able to then set off the filter both programmatically or through question string:

Submit::filter(['created_after_filter' => '2023-01-01'])->get();


// A number of filters


'created_after_filter' => '2023-01-01',

'published_filter' => true,



// Or by question string: /posts?created_after_filter=2023-01-01


This bundle consists of many options associated to filtering fashions, reminiscent of:

  • Group filtering
  • Filter validation
  • Sorting
  • Looking
  • Date filter kind
  • String filter kind
  • Choose filter kind
  • Numeric filter kind
  • Boolean filter kind
  • Trashed filter kind
  • Filtering on relations
  • And extra

To get began with this bundle, take a look at the official documentation; the supply code can also be on GitHub at lacodix/laravel-model-filter.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments