Download the PHP package zhylon/api-resources without Composer

On this page you can find all versions of the php package zhylon/api-resources. 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 api-resources

Zhylon API-Resources

Latest Stable Version Tests License

Small, opinionated helpers for building consistent, JSON:API-inspired API resource responses in Laravel:

Requirements

Installation

There is nothing to publish or configure — both classes are used directly.

Usage

Single resources — BuildsApiResource

Add the trait to a JsonResource and call toApiResource() from toArray():

produces:

toApiResource() accepts:

Parameter Type Description
type string The JSON:API-style resource type, e.g. 'order'
attributes array The resource's own attributes
selfHref ?string Value for links.self.href
timestamps bool Appends created_at/updated_at (as ISO-8601 strings) to attributes
id string\|int\|null Overrides automatic id resolution (see below)

Resolving the id

When id isn't passed explicitly, resolveResourceId() resolves it in this order:

  1. safeHashID() on the underlying resource, if it defines one.
  2. hashID(), if the underlying resource implements TobyMaxham\HashId\Interfaces\Hashing.
  3. The resource's primary key (getKey()), or its id property as a last resort.

None of this requires tobymaxham/laravel-hashid (or any other hashid package) to be installed — the checks use method_exists()/interface_exists(), so they simply no-op down the chain when unavailable.

For full custom control, override resolveResourceId() in your resource class:

Collections — ApiResourceCollection

Because BuildsApiResource overrides the static collection() method Laravel already gives every JsonResource, you don't need a dedicated collection class — just call it on your resource:

This returns an ApiResourceCollection (an AnonymousResourceCollection under the hood) that wraps the items in a data key and — exactly like Laravel's own paginated resource responses — adds links/meta automatically for both Illuminate\Pagination\LengthAwarePaginator and cursor paginators (Illuminate\Contracts\Pagination\CursorPaginator). Passing a plain collection instead of a paginator just returns { "data": [...] }, no extra setup required.

If you need a dedicated collection class (e.g. to add extra top-level meta), extend ApiResourceCollection directly and pass both the resource and the item class it collects into:

Testing

License

The MIT License (MIT). See LICENSE for more information.


All versions of api-resources with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^12.0 || ^13.0
illuminate/http Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.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 zhylon/api-resources contains the following files

Loading the files please wait ...