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

#[Sanitize]

Stage: TRANSFORM (2)

Applies one or more sanitization rules to the payload value in order. This is the most versatile transform attribute, supporting multiple chained operations.


Parameters

ParameterTypeRequiredDescription
...$rulesstring✅One or more sanitization rule names to apply

Supported Rules

RuleDescriptionExample
lowercaseConvert to lowercase"ACTIVE" → "active"
uppercaseConvert to uppercase"active" → "ACTIVE"
ucfirstCapitalize first letter"hello world" → "Hello world"
strip_tagsRemove HTML and PHP tags"<b>hello</b>" → "hello"
nl2brConvert newlines to <br> tags"a\nb" → "a<br>\nb"
slugConvert to URL-friendly slug"Hello World" → "hello-world"
trimRemove whitespace from both sides" hello " → "hello"

Usage

Single Rule

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

#[Sanitize('lowercase')]
protected function status(Payload $payload)
{
    // "ACTIVE" → "active"
    return $this->builder->where('status', $payload->value);
}

Multiple Rules (Applied in Order)

#[Sanitize('trim', 'strip_tags', 'lowercase')]
protected function status(Payload $payload)
{
    // "  <b>ACTIVE</b>  " → "active"
    return $this->builder->where('status', $payload->value);
}

Generate Slug

#[Sanitize('slug')]
protected function category(Payload $payload)
{
    // "Hello World Post" → "hello-world-post"
    return $this->builder->where('slug', $payload->value);
}

Rule Order Matters

Rules are applied left to right, so the order can affect the result:

// ✅ Correct: strip tags first, then lowercase
#[Sanitize('strip_tags', 'lowercase')]
// "<B>HELLO</B>" → "HELLO" → "hello"

// ⚠️ Different result: lowercase first, then strip tags
#[Sanitize('lowercase', 'strip_tags')]
// "<B>HELLO</B>" → "<b>hello</b>" → "hello"

Behavior

ScenarioResult
Value is a stringAll rules are applied in order
Value is not a stringNo modification (silently skipped)
Unknown rule nameInvalidArgumentException is thrown
Edit this page
Last Updated:
Contributors: kettasoft
Prev
Trim
Next
Cast