Warning
This is not ready for production usage.
The Schema package provides a flexible and intuitive way to define and manage data schemas in PHP. It allows developers to create structured schemas with various property types, including strings, integers, booleans, arrays, objects, and enums. The package supports nested schemas, inline enums, and backed enums, making it ideal for building complex data structures. Designed for Laravel, it integrates seamlessly with the framework and includes tools for configuration, migrations, and views.
You can install the package via composer:
composer require strucura/schema
<?php
use Strucura\Schema\Facades\Schema;
use Strucura\Schema\Enums\PropertyTypeEnum;
// Create an object schema
$schema = Schema::object()
// Add properties to the schema
->string('name', true) // Required string property
->integer('age', false) // Optional integer property
->enum('status', ['active', 'inactive'], true) // Required enum property
->float('price', true) // Required float property
->date('created_at', true) // Required date property
->object('address', function ($nested) {
$nested->string('street', true);
$nested->string('city', true);
}, false); // Optional nested object
// Convert the schema to an array
$schemaArray = $schema->toArray();
// Output the schema
print_r($schemaArray);
// Renders
[
'type' => 'object',
'properties' => [
'name' => [
'type' => 'string',
'required' => true,
],
'age' => [
'type' => 'integer',
'required' => false,
],
'status' => [
'type' => 'enum',
'required' => true,
'enum' => ['active', 'inactive'],
],
'price' => [
'type' => 'float',
'required' => true,
],
'created_at' => [
'type' => 'date',
'required' => true,
],
'address' => [
'type' => 'object',
'required' => false,
'properties' => [
'street' => [
'type' => 'string',
'required' => true,
],
'city' => [
'type' => 'string',
'required' => true,
],
],
],
],
];
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.