2017 © Pedro Peláez
 

library lmodel

Laravel Model (generator, constants, preserved lines, phpdoc)

image

corex/lmodel

Laravel Model (generator, constants, preserved lines, phpdoc)

  • Wednesday, April 25, 2018
  • by corex
  • Repository
  • 0 Watchers
  • 3 Stars
  • 362 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 11 Versions
  • 45 % Grown

The README.md

Model Generator for Laravel

Versioning for this package follows http://semver.org/. Backwards compatibility might break on upgrade to major versions., (*1)

Connects to your existing database and auto-generates models based on existing schema. - Support for multiple connections. - Support for auto-completion via magic properties (phpdoc). - Support for custom methods (preserved lines). - Support for guarded fields. - Support for custom "extends". - Support for extra field-attributes after magic properties. - Support for building constants in model. - Support for custom "indent". - Support for preserving $timestamps value. - Support for column of type "enum" (mapped to string)., (*2)

Note: Generating a model that already exists will overwrite existing model, but every line below "preserve" identifier, will be preserved., (*3)

Installation

Run "composer require corex/lmodel --dev"., (*4)

Add a configuration-file config/corex/lmodel.php and add following code to it. Modify it to suit your needs., (*5)

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., (*6)

Settings: - path - where models are saved. - namespace - namespace of models. - addConnection - true/false if name of database-connection should be applied to namespace/directory. Name will automatically be converted to PascalCase. - extends - Class to extend. - indent - (optional) String to use as indent i.e. "\t". Default 4 spaces. - length - (optional) Length of line before linebreak. Used in tables with many fields. - const - (optional) This section is used to specify connections and tables which should contains constants from content of table. - {connection} - (optional) Name of connection. - {table} - (optional) Name of table. - {id} - (required) Name of field to get value of constant. - {name} - (required) Name of field to get name of constant. - {prefix} - (optional) Prefix to add to each name of constant. - {suffix} - (optional) Suffix to add to each name of constant. - replace - (optional) Values to replace in name of constant., (*7)

To register it and make sure you have this option available for development only, add following code to AppServiceProviders@register method., (*8)

if ($this->app->environment() == 'local') {
    $this->app->register('CoRex\Laravel\Model\ModelServiceProvider');
}

Help

php artisan help make:models, (*9)

Arguments: - connection: Name of connection to generate models from. It will be added to namespace/path for separation of models per connection. It is possible to disable this by setting addConnection to false. Specify "." to generate from default connection. - tables: Comma separated table names to generate. Specify "." to generate all., (*10)

Options: - guarded: Comma separated list of guarded fields., (*11)

Examples

Generated model from table status with config., (*12)

<?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';
    }
}

The Versions

25/04 2018

dev-master

9999999-dev

Laravel Model (generator, constants, preserved lines, phpdoc)

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel generator model

25/04 2018

dev-develop

dev-develop

Laravel Model (generator, constants, preserved lines, phpdoc)

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel generator model

25/04 2018

1.1.2

1.1.2.0

Laravel Model (generator, constants, preserved lines, phpdoc)

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel generator model

13/12 2017

1.1.1

1.1.1.0

Laravel Model (generator, constants, preserved lines, phpdoc)

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel generator model

21/08 2017

1.1.0

1.1.0.0

Laravel Model (generator, constants, preserved lines, phpdoc)

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel generator model

21/08 2017

1.0.5

1.0.5.0

Laravel Model (generator, constants, preserved lines, phpdoc)

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel generator model

22/06 2017

1.0.4

1.0.4.0

Laravel Model (generator, constants, preserved lines, phpdoc)

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel generator model

09/06 2017

1.0.3

1.0.3.0

Laravel Model (generator, constants, preserved lines, phpdoc)

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel generator model

04/06 2017

1.0.2

1.0.2.0

Laravel Model (generator, constants, preserved lines, phpdoc)

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel generator model

01/06 2017

1.0.1

1.0.1.0

Laravel Model (generator, constants, preserved lines, phpdoc)

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel generator model

30/05 2017

1.0.0

1.0.0.0

Laravel Model (generator, constants, preserved lines, phpdoc)

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel generator model