This is the documentation for v2 but the latest version is v3 . You can switch versions in the menu on the left/at the top. Check your current version with the following command:
composer show lacodix/laravel-model-filter
String Filter
On this page
Create the 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.
Filter Modes
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);