- What does laravel-liberu/api include out of the box?
- The package targets consistent, versioned JSON APIs and ships with ready-made controllers, resource transformers, authentication scaffolding, filtering and pagination helpers. The goal is to remove the repetitive boilerplate that appears in almost every Laravel REST service. Endpoints are structured so they can be documented with OpenAPI tooling. You still own your domain models and business logic; the package handles the API layer conventions.
- How do I install laravel-liberu/api in a Laravel application?
- Install it with Composer using composer require laravel-liberu/api. Because the package is part of the Laravel Liberu ecosystem, check the version constraints in its composer.json to confirm it matches your Laravel release before running the install. After installation, publish any provided configuration or service provider registrations as described in the package documentation. Then register your versioned route files and point your transformers at your Eloquent models.
- Which Laravel versions are supported by laravel-liberu/api?
- Support is tied to the Laravel Liberu ecosystem release you install, so the authoritative answer is the illuminate/support constraint inside the package's composer.json for that version tag. Pin a package version that matches your application's Laravel major version rather than relying on the default constraint. If you are on an older Laravel release, check the changelog for the last tag that lists it as supported. Running composer why-not laravel-liberu/api is a quick way to spot a mismatch.
- How does API versioning work in laravel-liberu/api?
- Versioning is handled at the routing and resource layer, so you can expose paths such as /api/v1 and /api/v2 while keeping separate controllers and transformers per version. That lets you evolve response shapes without breaking existing clients. You register each version's routes and bind it to its own transformer set, and older versions stay frozen while new work happens in the current one. Deprecating a version is then a matter of removing its route group once clients have migrated.
- How do I customise the JSON response shape returned by the API?
- Response formatting goes through resource transformers, so the recommended approach is to extend or replace the provided transformer classes rather than editing controllers. Each transformer maps a model to the array that is serialised, which keeps your output consistent across endpoints. If you need a different envelope for meta or pagination data, adjust the shared response layer in one place. This keeps controllers thin and makes shape changes easy to review.
- Does laravel-liberu/api handle authentication for API endpoints?
- The package provides authentication scaffolding for API routes, which you connect to the guard or token driver your application already uses, such as Laravel Sanctum or Passport. Protected route groups are separated from public ones so middleware can be applied consistently per version. You still configure token issuance, expiry and abilities in your own auth setup. Always run protected endpoints behind HTTPS and review the middleware stack before going live.
- How do filtering and pagination work for API consumers?
- Filtering and pagination are driven by query string parameters, so clients can narrow result sets and page through large collections without custom endpoints. You whitelist which model attributes are filterable and sortable, which prevents clients from querying arbitrary columns. Pagination output is returned in a predictable structure that matches the transformer conventions. Keep an eye on indexes for any column you expose as a filter, since unindexed filters degrade quickly at scale.
- Can laravel-liberu/api generate OpenAPI or Swagger documentation?
- The package is designed to be OpenAPI-ready rather than a full documentation generator, meaning endpoints and transformers are structured so annotations or schema generation tools can consume them. In practice you pair it with a Laravel OpenAPI tool such as swagger-php or Scramble to produce the spec file. Consistent transformer output is what makes the generated schemas accurate. Treat the spec as part of your test surface so it does not drift from the actual responses.
- How should I test endpoints built with laravel-liberu/api?
- Use Laravel's HTTP testing helpers with PHPUnit or Pest to assert status codes, JSON structure and validation errors for each versioned route. RefreshDatabase with an in-memory SQLite connection keeps the suite fast, and actingAs or Sanctum's testing helpers handle authenticated requests. Assert on the transformer output keys rather than the full payload so refactors do not break unrelated tests. Add a test per version to catch accidental breaking changes before release.
- What are the alternatives to laravel-liberu/api?
- Many teams build the same layer manually with Laravel's native API resources, route model binding and pagination, which gives maximum control with no extra dependency. Packages such as Spatie's laravel-query-builder handle filtering and sorting, while tools like Scramble cover OpenAPI generation, so you can compose a stack instead of adopting a full convention. Laravel Liberu makes sense when you want the versioning, controllers, transformers and auth scaffolding to follow one opinionated structure. Compare maintenance activity and Laravel version support before committing either way.