1. Go to this page and download the library: Download ipagdevs/schema-builder library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ipagdevs / schema-builder example snippets
use IpagDevs\Model\Model;
use IpagDevs\Model\Schema\Schema;
use IpagDevs\Model\Schema\SchemaBuilder;
class Review extends Model
{
protected function schema(SchemaBuilder $schema): Schema
{
$schema->int('rating')->
// Parse data from an array
$review = Review::parse([
'rating' => 5,
'comment' => 'Excellent product!'
]);
// Get attributes
echo $review->get('rating'); // 5
echo $review->get('author'); // 'Anonymous' (from default)
// Parsing with missing N_PRETTY_PRINT);
// or
echo json_encode($review->jsonSerialize(), JSON_PRETTY_PRINT);
use IpagDevs\Model\Model;
use IpagDevs\Model\Schema\Schema;
use IpagDevs\Model\Schema\Mutator;
use IpagDevs\Model\Schema\SchemaBuilder;
use IpagDevs\Model\Schema\MutatorContext;
class Category extends Model
{
protected function schema(SchemaBuilder $schema): Schema
{
$schema->int('id')->$schema->bool('is_active')->default(true);
$schema->date('available_since', 'Y-m-d')-> An array of strings
$schema->int('alternate_ids')->list()->nullable(); // An array of integers
$schema->string('matrix')->list()->list()->nullable(); // An array of arrays of strings
// Hidden Attributes
$schema->string('internal_code')->hidden(); // Always hidden from jsonSerialize()
$schema->string('promo_code')->nullable()->hiddenIf(
fn($value, Product $model) => $model->get('price') > 100.0
);
// Relationships
$schema->has('category', Category::class)->
$product = Product::parse($productData);
$json = $product->jsonSerialize();
// $json will NOT contain 'internal_code'.
// 'promo_code' will be hidden because price > 100.
// 'category' and 'reviews' will be arrays of serialized data.
$array = $product->toArray();
// $array WILL contain 'internal_code'.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.