Laravel Model (generator, constants, preserved lines, phpdoc)
corex/lmodel is a Laravel package for laravel model (generator, constants, preserved lines, phpdoc).
It currently has 6 GitHub stars and 5.816 downloads on Packagist (latest version 1.1.2).
Install it with composer require corex/lmodel.
Discover more Laravel packages by corex
or browse all Laravel packages to compare alternatives.
Last updated
Versioning for this package follows http://semver.org/. Backwards compatibility might break on upgrade to major versions.
Connects to your existing database and auto-generates models based on existing schema.
Note: Generating a model that already exists will overwrite existing model, but every line below "preserve" identifier, will be preserved.
Run "composer require corex/lmodel --dev".
Add a configuration-file config/corex/lmodel.php and add following code to it. Modify it to suit your needs.
return [
'path' => base_path('app/Models'),
'namespace' => 'App\Models',
'addConnection' => true,
'extends' => \Illuminate\Database\Eloquent\Model::class,
'indent' => "\t",
'length' => 120,
'const' => [
'{connection}' => [
'{table}' => [
'id' => '{id}',
'name' => '{name}',
'prefix' => '{prefix}',
'suffix' => '{suffix}',
'replace' => [
'XXXX' => 'YYYY',
]
]
]
]
];
Note: old config/corex.php is still supported but not recommended.
Settings:
To register it and make sure you have this option available for development only, add following code to AppServiceProviders@register method.
if ($this->app->environment() == 'local') {
$this->app->register('CoRex\Laravel\Model\ModelServiceProvider');
}
php artisan help make:models
Arguments:
Options:
Generated model from table status with config.
<?php
namespace App\Models\Test;
use Illuminate\Database\Eloquent\Model;
/**
* @property integer $id [TYPE=INTEGER, NULLABLE=0, DEFAULT=""]
* @property string $name [TYPE=STRING, NULLABLE=0, DEFAULT=""]
* @property string $value [TYPE=STRING, NULLABLE=0, DEFAULT=""]
*/
class Status extends Model
{
// Constants.
const CONSTANT1 = 1;
const CONSTANT2 = 2;
const CONSTANT3 = 3;
const CONSTANT4 = 4;
// Attributes.
public $timestamps = false;
protected $connection = 'mysql';
protected $table = 'status';
protected $fillable = ['id', 'name', 'value'];
protected $guarded = [];
/* ---- Everything after this line will be preserved. ---- */
/**
* Preserve this method.
*
* @return string
*/
public function preserveThisMethod()
{
return 'preserved';
}
}