FilterableFilterable
Home
📦 Installation
  • Setting Up Filterable
  • Discover Command
  • Listing All Filters
  • Testing Filters
  • Inspecting Filterable Classes
  • Caching
GitHub
Home
📦 Installation
  • Setting Up Filterable
  • Discover Command
  • Listing All Filters
  • Testing Filters
  • Inspecting Filterable Classes
  • Caching
GitHub
  • Home
  • Introduction
  • Installation
  • Service Provider
  • How It Works
  • Engines

    • Invokable

      • Overview
      • Annotations

        • Overview
        • Authorize
        • SkipIf
        • Trim
        • Sanitize
        • Cast
        • DefaultValue
        • MapValue
        • Explode
        • Required
        • In
        • Between
        • Regex
        • Scope
    • Tree
    • Ruleset
    • Expression
  • Features

    • Lifecycle Hooks
    • Header-Driven Filter Mode
    • Auto Register Filterable Macro
    • Conditional Logic
    • Filter Aliases
    • Through callbacks
    • Auto Binding
    • Custom engines
    • Data Provisioning
  • Execution

    • Invoker
  • API Reference

    • Filterable
    • Filterable facade
    • Payload
    • Sorter
  • Caching

    • Overview
    • Getting Started
    • Strategies
    • Auto Invalidation
    • Cache Profiles
    • Scoping Cache
    • Monitoring Cached Items
    • API Reference
    • Examples
  • CLI

    • Setup Filterable
    • Discover Filters
    • Test Filter
    • List Filters
    • Inspect Filter
  • Exceptions
  • Event System
  • Profile Management
  • Profiler
  • Sorting
  • Authorization
  • Validation
  • Sanitization

#[Trim]

Stage: TRANSFORM (2)

Removes whitespace (or custom characters) from the payload value before the filter method executes.


Parameters

ParameterTypeRequiredDefaultDescription
$charactersstring❌" \t\n\r\0\x0B"Characters to trim
$sidestring❌'both'Side to trim: 'both', 'left', or 'right'

Usage

Basic — Trim Both Sides

use Kettasoft\Filterable\Engines\Foundation\Attributes\Annotations\Trim;

#[Trim]
protected function title(Payload $payload)
{
    // "  hello world  " → "hello world"
    return $this->builder->where('title', $payload->value);
}

Trim Left Only

#[Trim(side: 'left')]
protected function title(Payload $payload)
{
    // "  hello world  " → "hello world  "
    return $this->builder->where('title', $payload->value);
}

Trim Right Only

#[Trim(side: 'right')]
protected function title(Payload $payload)
{
    // "  hello world  " → "  hello world"
    return $this->builder->where('title', $payload->value);
}

Custom Characters

#[Trim(characters: '-')]
protected function slug(Payload $payload)
{
    // "---hello-world---" → "hello-world"
    return $this->builder->where('slug', $payload->value);
}

Behavior

ScenarioResult
Value is a stringWhitespace/characters are trimmed
Value is not a stringNo modification (silently skipped)
Edit this page
Last Updated:
Contributors: kettasoft
Prev
SkipIf
Next
Sanitize