PHPackages                             laracademy/generators - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. laracademy/generators

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

laracademy/generators
=====================

This package will generate a Laravel Model based on your database table itself, filling in the required fields automatically.

3.7(2y ago)355346.4k↓18.1%514MITPHPPHP &gt;=7.4

Since May 27Pushed 2y ago15 watchersCompare

[ Source](https://github.com/laracademy/generators)[ Packagist](https://packagist.org/packages/laracademy/generators)[ RSS](/packages/laracademy-generators/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (23)Used By (4)

Laracademy Generators
=====================

[](#laracademy-generators)

[![Latest Stable Version](https://camo.githubusercontent.com/ecb2d1e59070068ddd901cc338a22729f3ec5da00520f778f1e9461d4fb0d35c/68747470733a2f2f706f7365722e707567782e6f72672f6c617261636164656d792f67656e657261746f72732f762f737461626c65)](https://packagist.org/packages/laracademy/generators) [![Total Downloads](https://camo.githubusercontent.com/d22b5e0bcc6cbcd83ddeb70582bdfb9a5350f93d47cee9ada41a8e41b41a1e34/68747470733a2f2f706f7365722e707567782e6f72672f6c617261636164656d792f67656e657261746f72732f646f776e6c6f616473)](https://packagist.org/packages/laracademy/generators) [![Latest Unstable Version](https://camo.githubusercontent.com/2c7b53cf706196d8fbaded36bfd3c502a6f077e02cc3c63c8606453e8aa7b5d7/68747470733a2f2f706f7365722e707567782e6f72672f6c617261636164656d792f67656e657261746f72732f762f756e737461626c65)](https://packagist.org/packages/laracademy/generators) [![License](https://camo.githubusercontent.com/79e3313fea31ee83c655ed04c3436138495d025cd6e7af0ff6f2e6a08829e67a/68747470733a2f2f706f7365722e707567782e6f72672f6c617261636164656d792f67656e657261746f72732f6c6963656e7365)](https://packagist.org/packages/laracademy/generators)

**Laracademy Generators** - is a tool set that helps speed up the development process of a Laravel application.

**Author(s):**

- [Laracademy](https://laracademy.co) ([@laracademy](http://twitter.com/laracademy), )

Requirements
------------

[](#requirements)

1. PHP 7.4+
2. Laravel 6.\*
3. MySQL \*

\*\* For Laravel 5.\* please use the version 1.5

Usage
-----

[](#usage)

### Step 1: Install through Composer

[](#step-1-install-through-composer)

```
composer require "laracademy/generators" --dev

```

### Step 2: Artisan Command

[](#step-2-artisan-command)

Now that we have added the generator to our project the last thing to do is run Laravel's Arisan command

```
php artisan

```

You will see the following in the list

```
generate:modelfromtable

```

Commands
--------

[](#commands)

### generate:modelfromtable

[](#generatemodelfromtable)

This command will read your database table and generate a model based on that table structure. The fillable fields, casts, dates and even namespacing will be filled in automatically.

You can use this command to generate a single table, multiple tables or all of your tables at once.

This command comes with a bunch of different options, please see below for each parameter

- --table=
    - This parameter if filled in will generate a model for the given table
    - You can also pass in a list of tables using comma separated values
    - When omitted, **all** tables will generate a model
        - In this scenario you can optionally specify a whitelist/blacklist in `config/modelfromtable.php`
        - `migrations` table will be blacklisted by default
- --connection=
    - By default, if omitted, the default connection found in `config/database.php` will be used
    - To specify a connection, first ensure that it exists in your `config/database.php`
- --folder=
    - By default, all models are store in your *app/* directory. If you wish to store them in another place you can provide the relative path from your base laravel application.
    - Alternatively, use a lambda in `config/modelfromtable.php` to dynamically specify folder path
- --namespace=
    - By default, all models will have the namespace of `App\Models`
    - Alternatively, use a lambda in `config/modelfromtable.php` to dynamically specify namespace
- --debug=\[*true|false (default)*\]
    - Shows some more information while running
- --singular=\[*true|false (default)*\]
    - This will create a singular titled model, e.g. "Categories" -&gt; "Category"
- --overwrite=\[*true|false (default)*\]
    - Overwrite model file(s) if exists
- --timestamps=\[*true|false (default)*\]
    - whether to timestamp or not

Examples (CLI)
--------------

[](#examples-cli)

### Generating a single table

[](#generating-a-single-table)

```
php artisan generate:modelfromtable --table=users

```

### Generating a multiple tables

[](#generating-a-multiple-tables)

```
php artisan generate:modelfromtable --table=users,posts

```

### Changing to another connection found in `database.php`

[](#changing-to-another-connection-found-in-databasephp)

```
php artisan generate:modelfromtable --connection=spark

```

### Changing the folder where to /app/Models

[](#changing-the-folder-where-to-appmodels)

```
php artisan generate:modelfromtable --table=user --folder=app/Models

```

Configuration file for saving defaults, dynamic lambdas
-------------------------------------------------------

[](#configuration-file-for-saving-defaults-dynamic-lambdas)

A [config file](https://github.com/laracademy/generators/blob/master/config/modelfromtable.php) should be in your project's config folder (if not, you can easily create it). Through this, you can set defaults you commonly use to cut down on the input your command line call requires. Some fields, like `namespace`, accept a static value or, more powerfully, a lambda to generate dynamic values. Additional fields not available to the CLI are available in the config. See below.

### Whitelist/Blacklist (config only)

[](#whitelistblacklist-config-only)

Particularly large databases often have a number of tables that aren't meant to have models. These can easily be filtered through either the whitelist or blacklist (or both!). Laravel's "migrations" table is already included in the blacklist. One nice feature is that you can wildcard table names if that makes sense for your situation...

```
'blacklist' => ['migrations'];
'whitelist' => ['user_address', 'system_*'];
```

### Filename, using lambda

[](#filename-using-lambda)

Large databases sometimes use a pattern of prefixing for organization, which you can use to organize your model files through a lambda.

```
'filename' => fn(string $tableName) => Str::studly(Str::after($tableName, '_')),
```

In this example, 'system\_user' would generate the filename 'User'. *Note that this is also available through the CLI, but it probably doesn't make as much sense to set there.*

### Folder path, using lambda

[](#folder-path-using-lambda)

Using the last example, you can also organize the folder path using the prefix...

```
'folder' => (function (string $tableName) {
    $prefix = Str::studly(Str::before($tableName, '_'));
    $path = app()->path('Models') . "/{$prefix}";

    if (!is_dir($path)) {
        mkdir($path);
    }

    return $path;
}),
```

In this example, 'system\_user' would generate the folder path 'path/to/your/install/app/Models/System'

### Namespace, using lambda

[](#namespace-using-lambda)

Using the last example, you would want to then generate a matching namespace to the file path

```
'namespace' => fn(string $folderpath) => 'App/Models' . Str::after($folderpath, app()->path('Models')),
```

Therefore the folder path 'path/to/your/install/app/Models/System' would generate the namespace 'App\\Models\\System'

### Delimiter (config only)

[](#delimiter-config-only)

By default array values are delimited with a simple comma, but a common preference is to delimit with a newline as well.

```
'delimiter' => ",\n" . str_repeat(' ', 8),
```

Result:

```
class SomeModel extends Model
{
    protected $fillable = [
        'SomeField',
        'AnotherField',
        'YetAnotherField'
    ];
```

License
-------

[](#license)

ModelGen is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

### Bug Reporting and Feature Requests

[](#bug-reporting-and-feature-requests)

Please add as many details as possible regarding submission of issues and feature requests

### Disclaimer

[](#disclaimer)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity56

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~128 days

Recently: every ~185 days

Total

22

Last Release

941d ago

Major Versions

1.5 → 2.02019-10-02

2.3 → 3.02020-10-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c554112713a408512e3c5986a02d598f235daa4e6683c52b0b2ec873e6cb175?d=identicon)[Laracademy](/maintainers/Laracademy)

---

Top Contributors

[![michael-mcmullen](https://avatars.githubusercontent.com/u/811123?v=4)](https://github.com/michael-mcmullen "michael-mcmullen (18 commits)")[![danrovito](https://avatars.githubusercontent.com/u/8322674?v=4)](https://github.com/danrovito "danrovito (10 commits)")[![daverogers](https://avatars.githubusercontent.com/u/953524?v=4)](https://github.com/daverogers "daverogers (6 commits)")[![mrbig00](https://avatars.githubusercontent.com/u/1911197?v=4)](https://github.com/mrbig00 "mrbig00 (2 commits)")[![johnneijzen](https://avatars.githubusercontent.com/u/1343960?v=4)](https://github.com/johnneijzen "johnneijzen (2 commits)")[![OsamaMohammed](https://avatars.githubusercontent.com/u/19372520?v=4)](https://github.com/OsamaMohammed "OsamaMohammed (1 commits)")[![cyberhicham](https://avatars.githubusercontent.com/u/10002527?v=4)](https://github.com/cyberhicham "cyberhicham (1 commits)")[![mindspread](https://avatars.githubusercontent.com/u/514937?v=4)](https://github.com/mindspread "mindspread (1 commits)")[![mrzainulabideen](https://avatars.githubusercontent.com/u/31840471?v=4)](https://github.com/mrzainulabideen "mrzainulabideen (1 commits)")[![amphetkid](https://avatars.githubusercontent.com/u/675332?v=4)](https://github.com/amphetkid "amphetkid (1 commits)")

---

Tags

laravelgenerators

### Embed Badge

![Health badge](/badges/laracademy-generators/health.svg)

```
[![Health](https://phpackages.com/badges/laracademy-generators/health.svg)](https://phpackages.com/packages/laracademy-generators)
```

###  Alternatives

[laracasts/generators

Advanced Laravel generators, that include schema information.

2.4k6.4M44](/packages/laracasts-generators)[summerblue/generator

Extend Laravel's generators scaffold.

34139.9k](/packages/summerblue-generator)[zachleigh/laravel-vue-generators

Generate Vue js files via artisan commands.

9039.6k](/packages/zachleigh-laravel-vue-generators)[webfactor/laravel-generators

Laravel generators for quickly creating entities.

3011.1k](/packages/webfactor-laravel-generators)[mckenziearts/laravel-command

A simple Laravel package to provide artisan new commands

321.2k](/packages/mckenziearts-laravel-command)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
