Download the PHP package hatchyu/laravel-steward without Composer

On this page you can find all versions of the php package hatchyu/laravel-steward. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-steward

Laravel Steward

Latest Version on Packagist GitHub Tests Action Status Total Downloads License PHP 8.4+ Laravel 12+

Production-grade CQRS primitives, declarative HTTP query parsing, and native JSON:API stewardship for Laravel applications.

Overview

Laravel Steward is a lightweight, high-performance architecture toolkit designed for modern Laravel applications following CQRS principles. It provides clean abstractions for encapsulate-and-execute write actions, declarative read queries, strict request query parameter validation, and seamless JSON:API resource mapping built directly on top of Laravel's native HTTP resource system.

Key Features

[!IMPORTANT] Security & Authorization Boundaries
laravel-steward is a CQRS data orchestration and query engine, not an authorization or multi-tenancy boundary.

  • Authorization: Always perform Policy checks ($this->authorize(...) / Gate::authorize()) in your Controllers or Form Requests before passing models to Steward Actions.
  • Tenant Scoping: Ensure tenant-scoped global scopes or explicit query scoping (e.g., $user->team->customers()) are applied prior to executing Steward Queries or Actions. Steward assumes the model or query passed into its pipeline has already been authorized and scoped by your application.

Requirements

Installation

Install the package via Composer:

Optionally publish the configuration file:

The package registers:

through StewardServiceProvider.php.

Query parsing

QueryParamsParserContract auto-detects plain query strings vs JSON:API query format.

Plain format example:

Plain format also accepts filter as a JSON object string (unencoded / URL-encoded):

JSON:API format example:

JSON:API format also accepts filter as a JSON object string:

Notes:

Query Parameter Conventions

laravel-steward uses standard, fixed query parameter conventions across its parsers:

Parameter Type Format / Example Description
search string ?search=john Free-text search string. In JSON:API format, ?filter[search]=john is also supported.
filter array\|string Single value: ?filter[status]=active
Comma-separated: ?filter[id]=1,2,3,4,5
Array list: ?filter[id][]=1&filter[id][]=2
JSON string: ?filter={"status":"active"}
Filter criteria. Supports single scalars, array lists, comma-separated strings (1,2,3), or JSON object strings.
sort string\|array Comma-separated: ?sort=-created_at,name
JSON array: ?sort=["-created_at","name"]
Comma-separated string, array list, or JSON array string. Prefix - denotes descending order (desc).
include string ?include=addresses,orders.items Comma-separated list of relationship inclusion paths.
fields array\|string Bracket object: ?fields[customers]=name,email
JSON object: ?fields={"customers":["name","email"]}
Object keyed by JSON:API resource type specifying sparse fieldsets. Supports bracket syntax or JSON object strings.
page array\|string\|integer Plain: ?page=2&size=25
JSON:API: ?page[number]=2&page[size]=25
JSON object: ?page={"number":2,"size":25}
Page-number or cursor pagination. JSON:API requests require the page-object form.
page[cursor] string ?page[cursor]=eyJpZCI6MTB9 Cursor token string for cursor-based pagination.
size integer ?size=25 Top-level fallback parameter for page size.

Pagination and request-complexity limits are configured in steward.php. Defaults cap page size at 100, page number at 10,000, filter fields and sort fields at 20, values per filter at 100, includes at 20, requested sparse fields at 100, and individual query values at 2,048 bytes. Invalid or oversized values are rejected with validation errors; they are never silently ignored or clamped.

Convert a request into normalized query params:

The normalized result is Hatchyu\Steward\Queries\Params\QueryParams.

It includes:

For safety, list endpoints reject include and sparse fields[...] parameters unless the query or request declares them explicitly. When using StewardResource, its resource metadata supplies those allowlists automatically. Non-JSON:API queries can override GetModelQuery::allowedIncludes().

Query definitions

Use QueryDefinition to declare which fields can be searched, filtered, and sorted.

Simple strings work for common cases:

For mapped names or custom behavior, pass criteria objects:

Additional search strategies are also available for finer control:

PartialSearch, StartsWithSearch, and EndsWithSearch escape SQL LIKE wildcard characters (% and _) before querying.

Model queries

Use GetModelQuery or FindModelQuery for read flows.

Example:

When jsonApiResource() is configured, applyQueryParams() will:

Projection rules:

Relation-aware eager-load projection rules:

Current conservative behavior:

These are designed to pair with AbstractData request DTOs. When you already have an instantiated model (for example, from Route Model Binding or policy authorization), call executeModel() to avoid an unnecessary database lookup.

Model Finders (FindModelQuery)

FindModelQuery provides point-lookups by primary key:

Cursor Pagination

GetModelQuery supports both standard offset pagination (paginate()) and constant-time cursor pagination (cursorPaginate()):

When using cursorPaginateByQueryParams(), Steward appends the model primary key as a tie-breaker when the requested sort does not already include it. This keeps cursor traversal stable when a client sorts on non-unique values.

Data objects

AbstractData lets you map validated input into typed DTO-style objects.

It normalizes booleans, backed/unit enums, and concrete int, float, and string constructor properties. Validate request data before constructing DTOs; ambiguous union types intentionally retain PHP's native type resolution.

Use it for action payloads and request body transformation. The test suite includes examples of case conversion and nullable handling under tests/Unit/.

Steward Resources (StewardResource)

Extend Hatchyu\Steward\Resources\StewardResource for API response documents.

StewardResource provides smart auto-detection defaults and format-neutral methods that serve both Standard REST and JSON:API formats:

Smart Conventions & Auto-Detection:

Example Resource Implementation:

Return a single resource:

Return a collection:

Both single resource and collection responses set the matching HTTP headers (Content-Type: application/json for REST mode, Content-Type: application/vnd.api+json for JSON:API mode).

JSON:API request validation

ListQueryRequest can validate:

The preferred approach is to point the request at the primary JSON:API resource:

From that resource, the request derives:

The matching query can derive eager-loading from the same resource by overriding jsonApiResource().

That same resource metadata also powers conservative sparse-field projection for:

If needed, you can still override allowedIncludes() and allowedFields() directly.

Dual REST & JSON:API Format Support Engine

laravel-steward provides a built-in, configurable dual format engine supporting both Standard REST and JSON:API formats for incoming write payloads and outgoing HTTP responses transparently.

1. Format Resolution (ApiResponseFormatResolver)

The outgoing format is determined dynamically per HTTP request:

  1. Forced Middleware Attribute: Handled via steward_api_response_format request attribute.
  2. Query Parameter: e.g., ?format=jsonapi or ?format=rest (configurable key in steward.api.query_parameter).
  3. HTTP Accept Header: Accept: application/vnd.api+json yields JSON:API format.
  4. Configuration Default: Falls back to config('steward.api.default_format', 'rest').

2. Payload Normalization (JsonApiPayloadNormalizer)

Incoming write payloads (POST, PUT, PATCH) are processed in BaseActionRequest::prepareForValidation():

This allows Form Requests (BaseActionRequest), AbstractData DTOs, and CQRS Actions to remain 100% format-agnostic.

3. Dual Response Formatting (StewardResource & AnonymousResourceCollection)

Extending StewardResource automatically renders:

Both single resources and collections (CustomerResource::collection($customers)) automatically set the matching Content-Type header via AnonymousResourceCollection.

4. Format Enforcement Middleware

Design notes

Test Examples in this Repository

See the working integration and test suite in:


All versions of laravel-steward with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
illuminate/contracts Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0
illuminate/http Version ^12.0 || ^13.0
illuminate/database Version ^12.0 || ^13.0
illuminate/validation Version ^12.0 || ^13.0
hatchyu/laravel-api-exceptions Version ^0.2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hatchyu/laravel-steward contains the following files

Loading the files please wait ...