rayvenues/eloquent-model-generator
Pros:
$fillable, $casts, relationships) for rapid prototyping or legacy system modernization.Tenants/{tenant_id}/Models).Cons:
hasManyThrough).casts = ['password' => 'encrypted']).belongsTo from foreign keys).SERIAL vs. MySQL’s AUTO_INCREMENT).php artisan ray:generate:model in post-migrate hooks) to keep models in sync with schema changes.php artisan ray:check:schema User).App\Models namespace may conflict with existing models. Risk mitigated by customizable --namespace.--dry-run flag first.HasValidation) to isolate testable behavior.$guarded properties)?password_resets) that should be excluded from generation? Add a --ignore-tables flag or .gitignore-like config.$searchable traits.settings, logs) to validate output quality.post-migrate hook in AppServiceProvider to auto-generate models after schema changes:
public function boot()
{
Schema::defaultStringLength(191);
$this->generateModelsAfterMigrations();
}
protected function generateModelsAfterMigrations()
{
$tables = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames();
foreach ($tables as $table) {
$modelName = Str::studly($table);
Artisan::call("ray:generate:model {$modelName} --table-name={$table}");
}
}
app/Models/Concerns/GeneratedModel.php) to add consistent logic:
// app/Models/Concerns/GeneratedModel.php
trait GeneratedModel
{
public function getTable()
{
return config('eloquent.table_prefix') . parent::getTable();
}
}
Model::extend() to inject this trait into all generated models.composer.json constraints).casts definitions for complex types.boot() methods, custom scopes).users requires manual HasApiTokens trait").--dry-run mode (if available) or check generated files into Git to review changes.php artisan migrate).snake_case tables → StudlyCase models).MODEL_GENERATION.md file listing:
dd($model->getAttributes()) to inspect generated attributes.try-catch block around Artisan::call() to log failures:
try {
Artisan::call("ray:generate:model User");
} catch (\Exception $e) {
Log::error("Model generation failed: {$e->getMessage()}");
}
How can I help you explore Laravel packages today?