Package Data | |
---|---|
Maintainer Username: | corex |
Maintainer Contact: | dev@corex.dk (CoRex) |
Package Create Date: | 2017-05-22 |
Package Last Update: | 2020-09-26 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:06:32 |
Package Statistics | |
---|---|
Total Downloads: | 5,808 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 6 |
Total Watchers: | 1 |
Total Forks: | 1 |
Total Open Issues: | 1 |
Laravel Model (generator, constants, preserved lines, phpdoc).
Auto-generate models with constants, preserved lines, phpdoc, etc. for Laravel 5.
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';
}
}