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

#[Required]

Stage: VALIDATE (3)

Ensures the payload value is present and not empty. If the value is missing or empty, a StrictnessException is thrown, which propagates up rather than silently skipping.


Parameters

This attribute has no constructor parameters. The error message includes the parameter name automatically.


Usage

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

#[Required]
protected function status(Payload $payload)
{
    return $this->builder->where('status', $payload->value);
}

Error Message

When the value is empty, the exception message follows this format:

The parameter 'status' is required.

The parameter name (status) is taken from the filter key in the request.


Behavior

ScenarioResult
Value is providedFilter executes normally
Value is empty ('')StrictnessException is thrown
Value is nullStrictnessException is thrown

Warning

Unlike other validation attributes (like #[In] or #[Between]) which skip the filter silently, #[Required] throws a StrictnessException that propagates to the caller.


Combining with Other Attributes

#[Trim]                    // First: trim whitespace
#[Required]                // Then: ensure it's not empty after trimming
#[In('active', 'pending')] // Finally: validate allowed values
protected function status(Payload $payload)
{
    return $this->builder->where('status', $payload->value);
}
Edit this page
Last Updated:
Contributors: kettasoft
Prev
Explode
Next
In