PHP code example of grazulex / laravel-modelschema
1. Go to this page and download the library: Download grazulex/laravel-modelschema 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/ */
grazulex / laravel-modelschema example snippets
use Grazulex\LaravelModelschema\Services\SchemaService;
$schemaService = new SchemaService();
// Parse and separate core from extensions
$result = $schemaService->parseAndSeparateSchema($yamlContent);
// Returns: ['core' => [...], 'extensions' => [...]]
// Validate only the core schema
$errors = $schemaService->validateCoreSchema($yamlContent);
// Extract structured data for generation
$data = $schemaService->extractCoreContentForGeneration($yamlContent);
// 1. Generate complete YAML from stub + app data
$completeYaml = $schemaService->generateCompleteYamlFromStub(
'user.schema.stub',
['MODEL_NAME' => 'User', 'TABLE_NAME' => 'users'],
$appExtensionData
);
// 2. Validate the complete YAML (focuses on core section)
$errors = $schemaService->validateFromCompleteAppYaml($completeYaml);
// 3. Extract all generation data as insertable fragments
$generationData = $schemaService->getGenerationDataFromCompleteYaml($completeYaml);
// 4. Use fragments in your application
$modelFragment = json_decode($generationData['generation_data']['model']['json'], true);
$migrationFragment = json_decode($generationData['generation_data']['migration']['json'], true);
use Grazulex\LaravelModelschema\Support\FieldTypePluginManager;
$manager = new FieldTypePluginManager();
// Register a custom plugin
$manager->registerPlugin(new CustomFieldTypePlugin());
// Auto-discover plugins in specific paths
$manager->discoverPlugins([
'App\\FieldTypes\\*Plugin',
'Custom\\Packages\\*FieldTypePlugin'
]);
// Get all registered plugins
$plugins = $manager->getAllPlugins();