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

#[DefaultValue]

Stage: TRANSFORM (2)

Sets a fallback value when the payload value is empty or null. The filter method still executes, but with the default value instead of the empty input.


Parameters

ParameterTypeRequiredDescription
$valuemixed✅The default value to use as fallback

Usage

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

#[DefaultValue('active')]
protected function status(Payload $payload)
{
    // If status is empty → uses "active"
    return $this->builder->where('status', $payload->value);
}

With Numeric Default

#[DefaultValue(10)]
protected function perPage(Payload $payload)
{
    // If perPage is empty → uses 10
    return $this->builder->limit($payload->value);
}

Behavior

ScenarioResult
Value is empty or nullPayload value is set to the default
Value is provided (non-empty)Default is not applied, original kept

Combining with Other Attributes

#[DefaultValue('pending')]
#[In('active', 'pending', 'archived')]
protected function status(Payload $payload)
{
    // Empty input → "pending" → passes In validation
    return $this->builder->where('status', $payload->value);
}
Edit this page
Last Updated:
Contributors: kettasoft
Prev
Cast
Next
MapValue