Files
lucent-laravel/src/Commands/GenerateCollectionSchema.php
T

43 lines
1009 B
PHP
Raw Normal View History

2024-09-07 00:03:11 +03:00
<?php
namespace Lucent\Commands;
use Illuminate\Console\Command;
use Lucent\Primitive\Collection;
use Lucent\Schema\CollectionSchema;
class GenerateCollectionSchema extends Command
{
protected $signature = 'lucent:generate:collection {name}';
protected $description = 'Generate a lucent collection';
public function handle()
{
$name = $this->argument('name');
$schema = new CollectionSchema(
name: $name,
label: $name,
visible: [],
groups: [],
fields: Collection::make(),
);
$json = json_encode($schema, JSON_PRETTY_PRINT);
$configDir = base_path(config('lucent.schemas_path'));
$schemaPath = $configDir . "/" . $name . '.json';
if(file_exists($schemaPath)){
$this->error("The schema file already exists.");
return 0;
}
file_put_contents($schemaPath, $json);
$this->info("The schema file has been created.");
}
}