AthenaeumAthenaeum
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
  • Version 9.x

    • Release Notes
    • Upgrade Guide
    • New to this...
    • Contribution Guide
    • Security Policy
    • Code of Conduct
    • Origin
  • ACL

    • Introduction
    • How to install
    • Setup
    • Permissions
    • Roles
    • Users
    • Cached Permissions
  • Antivirus

    • Introduction
    • How to install
    • Setup
    • How to use
    • Scanners

      • Introduction
      • ClamAV
      • Null
      • Custom
    • Events
    • PSR
  • Audit

    • Audit
    • How to install
    • Setup
    • Recording
    • Events
  • Auth

    • Introduction
    • How to install
    • Fortify

      • Prerequisites
      • Exceptions

        • Failed Login Attempt
        • Password Reset Link Failure
      • Responses

        • Failed Password Reset Link
  • Circuits

    • Circuits
    • How to install
    • Setup
    • Usage
    • Events
  • Collections

    • Collections
    • How to install
    • Summation

      • Summation Collection
      • Items Processor
  • Config

    • Configuration Loader
    • How to install
    • Setup
    • Load Configuration Files
    • Custom File Parsers
  • Console

    • Command and Schedule Registration
    • How to install
    • Setup
    • Commands
    • Schedules
  • Container

    • IoC Service Container
    • How to install
    • Container
    • List Resolver
  • Core

    • Athenaeum Core Application
    • How to install
    • Setup
    • Usage

      • Configuration
      • Service Providers
      • Service Container
      • Events
      • Caching
      • Logging
      • Console
      • Task Scheduling
      • Exception Handling
      • Extending Core Application
      • Testing
  • Database

    • Introduction
    • How to install
    • Models

      • Instantiatable
      • Sluggable
    • Query

      • Criteria (Query Filter)
  • Dto

    • Data Transfer Object (DTO)
    • How to install
    • Create Interface
    • Implement DTO
    • How to use
    • Populate
    • Export
    • Json
    • Serialization
    • Nested DTOs
    • Array DTO
  • ETags

    • Introduction
    • How to install
    • Setup
    • ETags usage

      • How to use
      • Generators

        • Default Generator
        • Custom Generator
      • Eloquent Models
    • Http Request Preconditions

      • Introduction
      • Resource Context
      • Preconditions
      • Actions
      • RFC 9110

        • If-Match
        • If-Unmodified-Since
        • If-None-Match
        • If-Modified-Since
        • If-Range
      • Extensions

        • Introduction
        • Range
      • Range Validator
      • Download Stream
    • Macros
  • Events

    • Register Listeners and Subscribers
    • How to install
    • Setup
    • Listeners
    • Subscribers
  • Filters

    • Search Filter Utilities
    • Prerequisites
    • How to install
    • Setup
    • Processor
    • Filters Builder
    • Predefined Resources

      • Search Processor
      • Sorting Processor
      • Constraints Processor
      • Matching Processor
    • Tip: Create a base builder
  • Flysystem

    • Introduction
    • Database Adapter

      • Introduction
      • How to install
      • Setup
      • Data Deduplication
      • MIME-Type Detection
  • Http

    • Api

      • Http API
      • How to install
      • Setup
      • Resources

        • Introduction
        • Timestamps
        • Self-Link
        • Relations
        • Caching
        • Registrar
      • Requests

        • Introduction
        • List Resources
        • List Deleted
        • Show Resource
        • Create Resource
        • Update Resource
        • Delete Resource
        • List Related
        • Process Multiple Resources
        • Helpers
      • Middleware

        • Introduction
        • Request Must Be Json
        • Capture Fields To Select
        • Remove Response Payload
    • Clients

      • Http Clients
      • How to install
      • Setup
      • Basic Usage
      • Available Methods

        • Fluent Api
        • Protocol Version
        • Base Uri
        • Http Method and Uri
        • Headers
        • Accept & Content-Type
        • Authentication
        • Http Query
        • Payload Format
        • Payload
        • Attachments
        • Cookies
        • Response Expectations
        • Middleware
        • Conditions
        • Criteria
        • Redirects
        • Timeout
        • Debugging
        • Logging
        • Driver Options
        • Driver
      • Http Query Builder

        • Introduction
        • Select
        • Where
        • Dates
        • Include
        • Pagination
        • Sorting
        • Raw Expressions
        • Custom Grammar
    • Cookies

      • Http Cookies
      • How to install
      • Usage
    • Messages

      • Http Messages
      • How to install
      • Serializers
  • Maintenance

    • Modes

      • Maintenance Modes
      • How to install
      • Setup
      • Basic Usage
      • Available Drivers
  • Mime Types

    • MIME-Types
    • How to install
    • Setup
    • Usage
    • Drivers

      • Available Drivers
      • File Info
  • Properties

    • Properties Overload
    • How to install
    • Usage
    • Naming Convention
    • Properties Visibility
  • Redmine

    • Redmine Api Client
    • How to install
    • Setup
    • General Usage

      • Supported Operations
      • Fetch list of resources
      • Find
      • Fetch
      • Create new record
      • Update existing record
      • Delete existing record
      • Relations
    • Available Resources

      • Predefined Resources
      • Attachments
      • Enumerations
      • Issue Relations
      • Users
      • User Groups
      • Roles
      • Project Memberships
      • Versions (Milestones)
      • Issue Categories
      • Trackers
  • Service

    • Service Registrar
    • How to install
    • How to use
  • Streams

    • Streams
    • How to install
    • Setup
    • How to use

      • Introduction
      • Open and Close
      • Raw Resource
      • Seeking
      • Reading
      • Writing
      • Size
      • Truncate
      • Sync
      • Flush
      • Hash
      • MIME-Type
      • Filename
      • Output
      • Locking
      • Transactions
      • Meta
      • Misc
  • Support

    • Introduction
    • How to install
    • Laravel Aware-of Helpers

      • How to use
      • Enforce Via Interface
      • Custom Default
      • Pros and Cons
      • Available Helpers
    • Env File
    • Aware-of Properties

      • Generator
      • Available Aware-of Helpers
    • Live Templates
  • Testing

    • Introduction
    • How to install
    • Test Cases
    • Testing Aware-of Helpers
  • Translation

    • Introduction
    • How to install
    • Exporters

      • Introduction
      • Setup
      • How to use
      • Drivers

        • Introduction
        • Array
        • Lang.js (Array)
        • Lang.js (JSON)
        • Cache
  • Utils

    • Introduction
    • How to install
    • Array
    • Duration
    • Json
    • Math
    • Memory
    • Method Helper
    • Invoker
    • Populatable
    • String
    • Version
  • Validation

    • Introduction
    • How to install
    • Setup
    • Rules

      • Alpha-Dash-Dot
      • Date Format
      • Semantic Version
You are viewing documentation for an outdated version. It is no longer supported!

List Resources

The ListResourcesRequest abstraction is intended for "index" requests in which a list of paginated resources is shown.

  • Authorisation
  • Pagination
  • Filters Builder
  • Request Preconditions

Example Request

use Aedart\Contracts\Filters\Builder;
use Aedart\Http\Api\Requests\Resources\ListResourcesRequest;
use App\Models\User;

class ListUsers extends ListResourcesRequest
{
    public function authorisationModel(): string|null
    {
        return User::class;
    }

    public function filtersBuilder(): string|Builder|null
    {
        // Request filters builder...
        return null;
    }
}

Example Action

Route::get('/users', function (ListUsers $request) {
    return UserResource::collection(
        User::query()
            ->paginate($request->show)
    );
})->name('users.index');

Authorisation

The authorize() is implemented by default. It checks if current user is granted an index ability for given resource. From the above shown examples, a users.index ability is checked.

Pagination

Validation of pagination query parameters is automatically performed. To configure pagination, you can set the following properties in your request class.

class ListUsers extends ListResourcesRequest
{
    /**
     * Default amount of results to be shown,
     * when none requested
     *
     * @var int
     */
    protected int $defaultShow = 15;

    /**
     * Minimum allowed value for "show" property
     *
     * @var int
     */
    protected int $showMinimum = 1;

    /**
     * Maximum allowed value for "show" property
     *
     * @var int
     */
    protected int $showMaximum = 100;

    /**
     * Name of the query parameter that contains requested page
     *
     * @var string
     */
    public string $pageKey = 'page';

    /**
     * Name of the query parameter that contains requested amount
     * to be shown per page
     *
     * @var string
     */
    public string $showKey = 'show';

    // ...remaining not shown ...
}

You can access pagination related properties directly on the request instance.

Route::get('/users', function (ListUsers $request) {
    $page = $request->page;
    $pageKey = $request->pageKey;
    $show = $request->show;

    $users = User::query()
            ->paginate(
                perPage: $show,
                pageName: $pageKey,
                page: $page
            );

    // ...remaining not shown...  
});

Filters Builder

If your request supports filters, then you can return the class path or Builder instance, in the filtersBuilder() method.

use Aedart\Contracts\Filters\Builder;
use Aedart\Http\Api\Requests\Resources\ListResourcesRequest;
use App\Filters\UserFiltersBuilder;

class ListUsers extends ListResourcesRequest
{
    // ...previous not shown ...

    public function filtersBuilder(): string|Builder|null
    {
        return UserFiltersBuilder::class;
    }
}

In your route or controller action, use the applyFilters() to apply eventual requested filters, which are available in the $filters attribute.

Route::get('/users', function (ListUsersRequest $request) {
    return UserResource::collection(
        User::applyFilters($request->filters->all())
            ->paginate($request->show)
    );
});

See Database Query Filters for additional information.

Request Preconditions

Although support for Http Request Conditionals is possible for this kind of request, it is not recommended. You will be required to compute a reliable ETag and/or Last-Modified date for the filtered and paginated results. This can end up costing a lot of CPU cycles and thereby affect performance. Therefore, no preconditions evaluation is enabled by default, for this kind of request abstraction.

Despite the above-mentioned recommendation, if you still wish to support evaluation of request preconditions, then you should consider generating a unique ETag which takes the following into consideration:

  • The requested query parameters (e.g. filters and pagination).
  • The filtered and paginated resources (the resulting eloquent models with eventual eager-loaded relations).
  • The type of resource that is requested.

See Show Single Resource for examples of preconditions evaluation. In addition, you should also review the source code of \Aedart\Http\Api\Requests\Concerns\HttpConditionals (available in all request abstractions).

Lastly, it might be prudent to ignore generating a Last-Modified date, if you enable preconditions evaluation for a collection of filtered and paginated resources.

Edit page
Last Updated: 31/01/2026, 15:12
Contributors: alin, aedart
Prev
Introduction
Next
List Deleted