Laravel Rest Api 3.0 brings typed fields and metrics
Version 3.0 of the Laravel Rest Api package has been released. Built by Gautier Deleglise, the package keeps its core idea of turning Eloquent models into a REST API from a single resource class, but according to the report most of what sits underneath has been replaced.
The most visible change is in field definitions. In 2.x, a resource listed column names. In 3.0, resources declare typed fields such as Text, Integer, Number, Date, Enum and Json. The package uses that single declaration across validation, filtering and documentation, so a field's type only has to be written once instead of being repeated in several places.
The package's own documentation generator is gone. According to the article, 3.0 integrates with Scramble instead. Once Scramble is installed, /docs/api documents every endpoint of every resource with a typed body, field rules, request examples and error responses. The package's test suite sends those request examples to the API and validates each response against the generated document, so a mismatch between docs and API fails a test.
Metrics are another new addition. Declaring a metric on a resource creates its own route without any controller code. The Value, Trend, Partition, Progress and Table types cover counts, sums, averages, medians and percentiles, and they support date ranges, time zones, comparison with the previous period and a result cache. According to the report, a metric only counts the rows the current user is allowed to see, and the client can narrow the result further with the same filters used for search.
Actions, mutates, destroys, restores and force destroys can now ask the user to confirm before running. The endpoint responds with a 428 status, your message and a signed token; when the client sends the same request back with that token, it runs. No session or extra endpoint is involved. The release requires PHP 8.3+ and Laravel 13.30+, and applications on Laravel 12 should stay on 2.x.