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

#[Authorize]

Stage: CONTROL (1)

Requires authorization before the filter method executes. If authorization fails, the filter is skipped entirely.


Parameters

ParameterTypeRequiredDescription
$authorizestring✅Fully qualified class name implementing the Authorizable contract

Usage

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

#[Authorize(AdminOnly::class)]
protected function secretField(Payload $payload)
{
    return $this->builder->where('secret_field', $payload->value);
}

Authorizable Contract

The class passed to #[Authorize] must implement Kettasoft\Filterable\Contracts\Authorizable:

<?php

namespace App\Filters\Authorizations;

use Kettasoft\Filterable\Contracts\Authorizable;

class AdminOnly implements Authorizable
{
    public function authorize(): bool
    {
        return auth()->user()?->is_admin ?? false;
    }
}

Behavior

ScenarioResult
authorize() returns trueFilter method executes normally
authorize() returns falseFilter is skipped (SkipExecution is thrown)
Class doesn't implement AuthorizableInvalidArgumentException is thrown

Example: Role-Based Filter Access

class RoleFilter implements Authorizable
{
    public function authorize(): bool
    {
        return auth()->user()?->hasRole('manager');
    }
}

// In your filter class:
#[Authorize(RoleFilter::class)]
protected function salary(Payload $payload)
{
    return $this->builder->where('salary', '>=', $payload->value);
}
Edit this page
Last Updated:
Contributors: kettasoft
Prev
Overview
Next
SkipIf