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

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

cwssrl/eloquent-model-generator
===============================

Eloquent Model Generator

1.12.1(3y ago)11.2kMITPHPPHP ^7.4|^8.0

Since Apr 3Pushed 3y agoCompare

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

READMEChangelog (1)Dependencies (6)Versions (67)Used By (0)

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

[](#eloquent-model-generator)

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

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

[](#installation)

Step 1. Add Eloquent Model Generator to your project:

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

```

Step 2. Configure your database connection.

Usage
-----

[](#usage)

Use

```
php artisan cws: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 cws: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 cws: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 cws:generate:model User --base-class-name=Some\\Other\\Base\\Model

```

### 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

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

```
