2017 © Pedro Peláez
 

library laravel-model-generator

Laravel 5 model generator from existing schema

image

ignasbernotas/laravel-model-generator

Laravel 5 model generator from existing schema

  • Thursday, July 6, 2017
  • by ignasbernotas
  • Repository
  • 17 Watchers
  • 209 Stars
  • 108,473 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 71 Forks
  • 9 Open issues
  • 16 Versions
  • 7 % Grown

The README.md

Project abandoned

I'm very sorry to announce that I no longer have time to maintain this package. This project was originally created over a couple of days when I needed to migrate an existing project onto Laravel. Even though it's being actively used (over 50k installs!), I can't find the time to keep track of the PRs and what changes might break things in new/old Laravel versions, nor have I had the need to use it after the initial release. The codebase is a mess and it desperately cries for a rewrite., (*1)

Please use reliese/laravel package instead., (*2)


Model Generator

Laravel 5 model generator for an existing schema., (*3)

It plugs into your existing database and generates model class files based on the existing tables., (*4)

Installation

composer require ignasbernotas/laravel-model-generator --dev

You'll only want to use these generators for local development, so you don't want to update the production providers array in config/app.php. Instead, add the provider in app/Providers/AppServiceProvider.php, like so:, (*5)

<?php

public function register()
{
    if ($this->app->environment() == 'local') {
        $this->app->register('Iber\Generator\ModelGeneratorProvider');
    }
}

Help & Options

php artisan help make:models

Usage:
  make:models [options]

Options:
      --tables[=TABLES]          Comma separated table names to generate
      --prefix[=PREFIX]          Table Prefix [default: DB::getTablePrefix()]
      --dir[=DIR]                Model directory [default: "Models/"]
      --extends[=EXTENDS]        Parent class [default: "Illuminate\Database\Eloquent\Model"]
      --fillable[=FILLABLE]      Rules for $fillable array columns [default: ""]
      --guarded[=GUARDED]        Rules for $guarded array columns [default: "ends:_guarded"]
      --timestamps[=TIMESTAMPS]  Rules for $timestamps columns [default: "ends:_at"]
  -i, --ignore[=IGNORE]          Ignores the tables you define, separated with ,
  -f, --force[=FORCE]            Force override [default: false]
  -s, --ignoresystem             If you want to ignore system tables.
                                              Just type --ignoresystem or -s
  -m, --getset                   Defines if you want to generate set and get methods
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --env[=ENV]                The environment the command should run under.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  Build models from existing schema.

Running the generator

php artisan make:models

Examples

Table users

SQL

CREATE TABLE `users` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(64) NULL DEFAULT NULL,
    `password` VARCHAR(45) NULL DEFAULT NULL,
    `email` VARCHAR(45) NULL DEFAULT NULL,
    `name` VARCHAR(45) NULL DEFAULT NULL,
    PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

Generated Models/Users.php class

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Users extends Model {

    public $timestamps = false;

    protected $table = 'users';

    protected $fillable = ['username', 'email', 'name'];

    protected $guarded = ['id', 'password'];

}

Table posts

SQL

CREATE TABLE `posts` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `title` VARCHAR(64) UNSIGNED NOT NULL DEFAULT '',
    `content` TEXT NOT NULL DEFAULT '',
    `created_at` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
    `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

Generated Models/Posts.php class

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Posts extends Model {

    public $timestamps = true;

    protected $table = 'posts';

    protected $fillable = ['title', 'content', 'created_at', 'updated_at'];

    protected $guarded = ['id'];

}

The Versions

06/07 2017

dev-master

9999999-dev

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

06/04 2017

1.2.3

1.2.3.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

16/03 2017

1.2.2

1.2.2.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

11/03 2017

1.2.1

1.2.1.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

06/03 2017

1.2.0

1.2.0.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

06/03 2017

1.1.5

1.1.5.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

24/05 2016

1.1.4

1.1.4.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

18/05 2016

1.1.3

1.1.3.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

26/04 2016

1.1.2

1.1.2.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

20/04 2016

1.1.1

1.1.1.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

29/02 2016

1.1

1.1.0.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

27/12 2015

1.0.3

1.0.3.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

12/11 2015

1.0.2

1.0.2.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

12/11 2015

1.0.1

1.0.1.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

08/10 2015

1.0

1.0.0.0

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model

08/10 2015

dev-hotfix

dev-hotfix

Laravel 5 model generator from existing schema

  Sources   Download

MIT

The Requires

 

laravel schema generator model