Download the PHP package mutado/laravel-resource-schema without Composer
On this page you can find all versions of the php package mutado/laravel-resource-schema. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-resource-schema
laravel-resource-schema
Laravel Resource Schema is a package that extends Laravel's API Resources, providing a flexible and powerful way to define and control the structure of your API responses.
This package was created with a huge support from Hidden Planet Productions.
Features:
- Define schema types for your resources
- Include properties dynamically
- Support for nested resources
- Optional properties that can be included on demand
- Easy to use with existing Laravel projects
Installation
You can install the package via composer:
Usage
Basic Usage
-
Create a new resource that extends SchemaResource:
- Use the resource in your controller:
Nested Resources
You can define how to include nested resources in your schema
Optional Properties
You can define optional properties in you schema type and include them on demand using the '?' prefix:
Custom Schema
If really need a custom schema for a specific request, you can define it using the useSchemaType
method and by passing a schema array:
Schema Property Syntax
The Laravel Resource Schema package uses a simple but powerful syntax for defining schemas. Here's a breakdown of the schema syntax:
property
- A basic property is defined simply by its name?property
- Optional properties are prefixed with a question mark?
nested_resource.nested_property
- You can include nested properties using dot notationnested_resource[nested_property1, nested_property2]
- or array syntaxnested_resource.*
- To include all properties of a nested resource, use the wildcard*
nested_resource/mini
- You can specify a schema for a nested resource
Combining these syntaxes allows you to define complex and flexible schemas for your resources.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is open-sourced software licensed under the MIT license.