/laravel-api-tool-kit:add-filterfrom laravel-api-tool-kit
Adds filtering, sorting, and search to an existing model's list endpoint. Detects project structure, creates or updates filter classes, and wires them into the controller.
Claude never picks this command on its own
Its frontmatter has no description. Without a description, Claude Code leaves it out of the list Claude chooses from. Typing /laravel-api-tool-kit:add-filter still runs it.
Use this when an existing model needs filtering, sorting, or search added to its list endpoint.
ls app/
Domain/ present → DDD: filters live in app/Domain/{Model}/Filters/{Model}Filters.phpDomain/ → Standard: filters live in app/Filters/{Model}Filters.phpCheck the existing model file to confirm — it will have protected string $default_filters = ... pointing to the correct namespace if a filter already exists.
Standard: look for app/Filters/{Model}Filters.php
DDD: look for app/Domain/{Model}/Filters/{Model}Filters.php
Follow rules/filters.md for the correct structure.
Standard: app/Filters/CarFilters.php
DDD: app/Domain/Car/Filters/CarFilters.php
Open the Model and ensure:
use App\Filters\CarFilters;
use Essa\APIToolKit\Filters\Filterable;
class Car extends Model
{
use Filterable;
protected string $default_filters = CarFilters::class;
}
Both use Filterable and protected string $default_filters are required.
Based on the requirement, fill in the appropriate arrays:
Add equality filters (?color=red&is_active=1):
protected array $allowedFilters = ['color', 'is_active', 'user_id'];
Add sort columns (?sorts=name or ?sorts=-created_at):
protected array $allowedSorts = ['name', 'created_at'];
Add eager-load includes (?includes=user,tags):
protected array $allowedIncludes = ['user', 'tags'];
Add text search columns (?search=keyword):
protected array $columnSearch = ['name', 'description'];
Add relationship search (?search=keyword):
protected array $relationSearch = [
'user' => ['first_name', 'last_name'],
];
Add a custom filter for non-trivial conditions:
// ?year=2023
public function year(string $term): void
{
$this->builder->whereYear('manufactured_at', $term);
}
Open the controller's index method and replace any manual query building with:
public function index(): AnonymousResourceCollection
{
return CarResource::collection(Car::useFilters()->dynamicPaginate());
}
Do NOT hardcode ->with(['user', 'tags']) here if those relationships are in $allowedIncludes. The client requests them via ?includes=user,tags and the filter class handles eager loading automatically. Hardcoding with() always loads relations even when not needed.
Filterable trait is on the model$default_filters is bound on the model$allowedFilters / $allowedSorts are populateduseFilters()->dynamicPaginate() — not ->get() or ->paginate()$this->builder — they return nothingWhat the command file sets; muted values are Claude Code's defaults
7-day visitors to each command page
Generated from the plugin's indexed repository (ahmedesa/laravel-api-tool-kit) — no native marketplace selected
npx claudepluginhub p/ahmedesa-laravel-api-tool-kit9 commands in this plugin
/code-reviewWorkflow: Code ReviewA defense-oriented multi-phase code review. Validates feature completeness against acceptance criteria, catches real bugs (not just style), and separates introduced issues from pre-existing debt./create-workflowWorkflow: Create a New WorkflowUse this when you discover a repeatable process during a session — an investigation type, a setup procedure, a debugging pattern — that should be captured as a reusable workflow./curl-testWorkflow: Test an API Endpoint with CurlUse during investigation or feature verification to test an endpoint directly and cross-reference its response against the database./investigateWorkflow: Investigate & DebugStructured debugging workflow for any issue — wrong response, missing data, queue failures, auth problems, performance issues. Works for any Laravel API project./new-endpointWorkflow: Add a New CRUD EndpointFollow these steps in order. Do not skip steps or reorder them./organize-knowledgeWorkflow: Organize Knowledge BaseConsolidates scattered investigation docs, notes, and findings into the correct knowledge files. Prevents knowledge sprawl and ensures ONE file per feature.Other plugins' commands for the same job