PHPackages                             defyma/eloquent-model-generator - 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. [Database &amp; ORM](/categories/database)
4. /
5. defyma/eloquent-model-generator

ActiveLibrary[Database &amp; ORM](/categories/database)

defyma/eloquent-model-generator
===============================

Eloquent Model Generator

013PHP

Since Oct 28Pushed 4y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Eloquent Model Generator
========================

[](#eloquent-model-generator)

Eloquent Model Generator is a tool based on [Code Generator](https://github.com/krlove/code-generator) for generating Eloquent models.

Installation
------------

[](#installation)

Step 1. Add Eloquent Model Generator to your project:

```
composer require krlove/eloquent-model-generator --dev

```

Step 2. Register `GeneratorServiceProvider`:

```
'providers' => [
    // ...
    Krlove\EloquentModelGenerator\Provider\GeneratorServiceProvider::class,
];
```

If you are using Laravel version 5.5 or higher this step can be omitted since this project supports [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery) feature.

Step 3. Configure your database connection.

Usage
-----

[](#usage)

Use

```
php artisan krlove:generate:model User

```

to generate a model class. Generator will look for table with name `users` and generate a model for it.

### table-name

[](#table-name)

Use `table-name` option to specify another table name:

```
php artisan krlove:generate:model User --table-name=user

```

In this case generated model will contain `protected $table = 'user'` property.

### output-path

[](#output-path)

Generated file will be saved into `app` directory of your application and have `App` namespace by default. If you want to change the destination and namespace, supply the `output-path` and `namespace` options respectively:

```
php artisan krlove:generate:model User --output-path=/full/path/to/output/directory --namespace=Some\\Other\\NSpace

```

`output-path` can be absolute path or relative to project's `app` directory. Absolute path must start with `/`:

- `/var/www/html/app/Models` - absolute path
- `Models` - relative path, will be transformed to `/var/www/html/app/Models` (assuming your project app directory is `/var/www/html/app`)

### base-class-name

[](#base-class-name)

By default generated class will be extended from `Illuminate\Database\Eloquent\Model`. To change the base class specify `base-class-name` option:

```
php artisan krlove:generate:model User --base-class-name=Some\\Other\\Base\\Model

```

### backup

[](#backup)

Save existing model before generating a new one

```
php artisan krlove:generate:model User --backup

```

If `User.php` file already exist, it will be renamed into `User.php~` first and saved at the same directory. After than a new `User.php` will be generated.

### Other options

[](#other-options)

There are several useful options for defining several model's properties:

- `no-timestamps` - adds `public $timestamps = false;` property to the model
- `date-format` - specifies `dateFormat` property of the model
- `connection` - specifies connection name property of the model

### Overriding default options globally

[](#overriding-default-options-globally)

Instead of spcifying options each time when executing the command you can create a config file named `eloquent_model_generator.php` at project's `config` directory with your own default values. Generator already contains its own config file at `Resources/config.php` with following options:

```
