### Installing Laravel JSON Schema Package Source: https://github.com/carsdotcom/laravel-json-schema/blob/development/README.md This command installs the `carsdotcom/laravel-json-schema` package into your Laravel project using Composer, making its functionalities available for use. ```Bash composer require carsdotcom/laravel-json-schema ``` -------------------------------- ### Sample JSON Data for Product Validation Source: https://github.com/carsdotcom/laravel-json-schema/blob/development/README.md This JSON object represents sample data for a product, containing `productId`, `productName`, and `price`. It is used as an example input to demonstrate how the `laravel-json-schema` validator processes data against a defined schema. ```JSON { "productId": 1, "productName": "An ice sculpture", "price": 12.50 } ``` -------------------------------- ### Example Product JSON Schema Definition Source: https://github.com/carsdotcom/laravel-json-schema/blob/development/README.md This JSON schema defines the structure for a 'Product' object, specifying properties like `productId` (integer), `productName` (string), and `price` (number with exclusive minimum of 0). It marks all three properties as required and is intended to be stored as `Product.json` in the `app/Schemas` folder. ```JSON { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://example.com/product.schema.json", "title": "Product", "description": "A product from Acme's catalog", "type": "object", "properties": { "productId": { "description": "The unique identifier for a product", "type": "integer" }, "productName": { "description": "Name of the product", "type": "string" }, "price": { "description": "The price of the product", "type": "number", "exclusiveMinimum": 0 } }, "required": [ "productId", "productName", "price" ] } ``` -------------------------------- ### Configuring Filesystem Disk for JSON Schemas in Laravel Source: https://github.com/carsdotcom/laravel-json-schema/blob/development/README.md This PHP configuration snippet defines a new local disk named 'schemas' within `config/filesystem.php`. It points the root directory for schema files to `app/Schemas`, which is essential for the `laravel-json-schema` package to locate and load schemas. ```PHP 'disks' => [ 'schemas' => [ 'driver' => 'local', 'root' => app_path('app/Schemas'), // must match the 'config.json-schema.local_base_prefix' value ] ] ``` -------------------------------- ### Storing a JSON Schema File for a Customer Source: https://github.com/carsdotcom/laravel-json-schema/blob/development/README.md This PHP snippet is presented under the context of storing a JSON schema file. It appears to be intended to associate the provided `$jsonSchemaForCustomer` data with the key 'Customer.json' within the `SchemaValidator`'s storage mechanism, making it available for future validation operations. ```PHP use Carsdotcom\JsonSchemaValidation\SchemaValidator; SchemaValidator::getSchemaContents('Customer.json', $jsonSchemaForCustomer); ``` -------------------------------- ### Validating JSON Data Against a Schema in Laravel Source: https://github.com/carsdotcom/laravel-json-schema/blob/development/README.md This PHP snippet demonstrates how to validate a given JSON data (`$json`) against a hosted schema file (`Product.json`) using the `SchemaValidator` facade. The `validateOrThrow` method will throw an exception if the data does not conform to the specified schema. ```PHP use Carsdotcom\JsonSchemaValidation\SchemaValidator; SchemaValidator::validateOrThrow($json, 'Product.json'); ``` -------------------------------- ### Retrieving Content of a Hosted JSON Schema File Source: https://github.com/carsdotcom/laravel-json-schema/blob/development/README.md This PHP code uses the `SchemaValidator` facade to retrieve the raw content of a specified JSON schema file, such as `Product.json`, from the configured schema storage location. This can be useful for inspecting or processing schema definitions directly. ```PHP use Carsdotcom\JsonSchemaValidation\SchemaValidator; SchemaValidator::getSchemaContents('Product.json'); ``` -------------------------------- ### Registering an In-Memory JSON Schema Source: https://github.com/carsdotcom/laravel-json-schema/blob/development/README.md This PHP code registers a raw JSON schema (`$jsonSchema`) directly into the `SchemaValidatorService`'s in-memory storage. This allows for immediate validation against a schema without needing to save it to a file, returning a key that can be used to reference the schema. ```PHP $schemaKey = (new SchemaValidatorService)->registerRawSchema($jsonSchema); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.