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

#[MapValue]

Stage: TRANSFORM (2)

Maps incoming values to different output values using a key-value map. Useful for converting human-readable values (like 'active', 'inactive') to database values (like 1, 0).


Parameters

ParameterTypeRequiredDefaultDescription
$maparray✅—Key-value mapping (e.g., ['active' => 1])
$strictbool❌falseIf true, skip the filter when value is not in the map

Usage

Basic Mapping

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

#[MapValue(['active' => 1, 'inactive' => 0])]
protected function status(Payload $payload)
{
    // "active" → 1, "inactive" → 0
    return $this->builder->where('status', $payload->value);
}

String to String Mapping

#[MapValue(['published' => 'live', 'draft' => 'hidden'])]
protected function visibility(Payload $payload)
{
    // "published" → "live", "draft" → "hidden"
    return $this->builder->where('visibility', $payload->value);
}

Strict Mode

When strict: true, if the incoming value is not found in the map, the filter is skipped entirely:

#[MapValue(['active' => 1, 'inactive' => 0], strict: true)]
protected function status(Payload $payload)
{
    // "unknown" → filter is SKIPPED
    return $this->builder->where('status', $payload->value);
}

Behavior

ScenarioNon-Strict (default)Strict Mode
Value exists in mapValue is replaced with mapped valueValue is replaced
Value does not exist in mapOriginal value is keptFilter is skipped
Edit this page
Last Updated:
Contributors: kettasoft
Prev
DefaultValue
Next
Explode