PHPackages                             rayvenues/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. rayvenues/eloquent-model-generator

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

rayvenues/eloquent-model-generator
==================================

Eloquent Model Generator

v1.0.2(3y ago)1325.6k↓48.3%2[2 issues](https://github.com/rayVenues/eloquent-model-generator/issues)1MITPHPPHP ^8.1

Since Jun 7Pushed 3y ago3 watchersCompare

[ Source](https://github.com/rayVenues/eloquent-model-generator)[ Packagist](https://packagist.org/packages/rayvenues/eloquent-model-generator)[ RSS](/packages/rayvenues-eloquent-model-generator/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (7)Versions (5)Used By (1)

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

[](#eloquent-model-generator)

Eloquent Model Generator generates Eloquent models using database schema as a source.

Version 1.0.0
-------------

[](#version-100)

Version 1.0.0 has been released.

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

[](#installation)

Step 1. Configure your database connection. Run your migrations.

Step 2. Add Eloquent Model Generator to your project:

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

Usage
-----

[](#usage)

Use

```
php artisan ray:generate:model User
```

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

### table-name

[](#table-name)

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

```
php artisan ray: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/Models` directory of your application and have `App\Models` namespace by default. If you want to change the destination and namespace, supply the `output-path` and `namespace` options respectively:

```
php artisan ray:generate:model User --output-path=/full/path/to/output/directory --namespace=Your\\Custom\\Models\\Place
```

`--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
- `Custom/Models` - relative path, will be transformed to `/var/www/html/app/Custom/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 ray:generate:model User --base-class-name=Custom\\Base\\Model
```

### no-backup

[](#no-backup)

If `User.php` file already exist, it will be renamed into `User.php~` first and saved at the same directory. Unless `--no-backup` option is specified:

```
php artisan ray:generate:model User --no-backup
```

### no-timestamps

[](#no-timestamps)

If you want to disable timestamps for the model, specify `--no-timestamps` option:

```
php artisan ray:generate:model User --no-timestamps
```

### date-format

[](#date-format)

If you want to specify date format for the model, specify `--date-format` option:

```
php artisan ray:generate:model User --date-format='Y-m-d'
```

### connection

[](#connection)

If you want to specify connection name for the model, specify `--connection` option:

```
php artisan ray:generate:model User --connection='mysql'
```

### Overriding default options

[](#overriding-default-options)

Instead of specifying options each time when executing the command you can publish the config file by executing the following command:

```
php artisan vendor:publish --provider="Ray\EloquentModelGenerator\Provider\GeneratorServiceProvider"
```

This will create a file named `eloquent_model_generator.php` at project's `config` directory. You can modify the file with your own default values:

```
