Download the PHP package gdebrauwer/laravel-hateoas without Composer
On this page you can find all versions of the php package gdebrauwer/laravel-hateoas. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gdebrauwer/laravel-hateoas
More information about gdebrauwer/laravel-hateoas
Files in gdebrauwer/laravel-hateoas
Package laravel-hateoas
Short Description Expose the authorization logic of your REST API using HATEOAS links on your Laravel API resources
License MIT
Homepage https://github.com/gdebrauwer/laravel-hateoas
Informations about the package laravel-hateoas
Laravel HATEOAS
HATEOAS allows you to expose the authorization logic of your REST API. This package makes it easy to add HATEOAS links to your Laravel API resources.
Each resource has its HATEOAS links, and only the accessible links per resource are returned. If a link is not available on a resource, then the clients of your API can disable functionality linked to that HATEOAS link.
By default an array of links, in the following format, will be added to the JSON of a Laravel API resource:
Installation
You can install the package via composer:
Usage
You can create a new HATEOAS class for a model using the following artisan command:
In the created class you can define public methods that will be used to generate the links. A method should either return a link or null
.
To add the links to an API resource, you have to add the HasLinks
trait and use the $this->links()
method. The HATEOAS class will be automatically discovered.
Customization
Formatting
You can customize the JSON links formatting by providing a formatter class that implements the Formatter
interface to the formatLinksUsing
method.
If the code to format the links is pretty small or you don't want to create a separate formatter class for it, you also have the option to provide a formatting callback function to the formatLinksUsing
method.
HATEOAS class discovery
By default, the HATEOAS classes of models will be auto-discovered. Specifically, the HATEOAS classes must be in a Hateoas directory below the directory that contains the models. If you would like to provide your own HATEOAS class discovery logic, you can register a custom callback:
Testing
Linting
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
- Günther Debrauwer
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-hateoas with dependencies
illuminate/support Version ^9.0|^10.0|^11.0
illuminate/routing Version ^9.0|^10.0|^11.0
spatie/once Version ^3.0