laravel-model-filter

This is the documentation for v2 but the latest version is v3 . You can switch versions in the menu at the top. Check your current version with the following command:

composer show lacodix/laravel-model-filter

String Filter

php artisan make:filter TestStringFilter -t string -f fieldname

this creates a filter class that extends StringFilter

<?php

namespace App\Models\Filters;

use Lacodix\LaravelModelFilter\Filters\StringFilter;

class TestStringFilter extends StringFilter
{
    protected string $field = 'fieldname';
}

A fieldname must be set, this will apply a where query to the model-query where fieldname contains the given value.

Default mode is LIKE

<?php

namespace App\Models\Filters;

use Lacodix\LaravelModelFilter\Enums\FilterMode;
use Lacodix\LaravelModelFilter\Filters\DateFilter;

class TestDateFilter extends DateFilter
{
    public FilterMode $mode = FilterMode::STARTS_WITH;

    protected string $field = 'fieldname';
}

Allowed modes are

  • FilterMode::STARTS_WITH;
  • FilterMode::ENDS_WITH;
  • FilterMode::EQUAL;
  • FilterMode::LIKE (default);