PHPackages                             abevanation/reversify - 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. abevanation/reversify

ActiveLaravel-library[Database &amp; ORM](/categories/database)

abevanation/reversify
=====================

Reverse engineer an existing database schema into Laravel migrations, models, services, and controllers

v1.0.4(1y ago)04MITPHPPHP ^8.0

Since Jan 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bevanr01/reversify)[ Packagist](https://packagist.org/packages/abevanation/reversify)[ RSS](/packages/abevanation-reversify/feed)WikiDiscussions main Synced 1mo ago

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

Reversify
=========

[](#reversify)

> **Note**
> Reversify is still in testing. Functionality may be unstable at best. If you would like to assist in getting this project off the ground, feel free to fork and submit pull requests for new features, bug fixes, or improvements.

[![Packagist Version](https://camo.githubusercontent.com/d6e2dc61adc21cbb0dc5b74416957c6b67e772eb63505fa52b63576244d19ffa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61626576616e6174696f6e2f726576657273696679)](https://camo.githubusercontent.com/d6e2dc61adc21cbb0dc5b74416957c6b67e772eb63505fa52b63576244d19ffa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61626576616e6174696f6e2f726576657273696679)[![Downloads](https://camo.githubusercontent.com/98378bf18668b5ce54ebdb89e0b1ce6d84208f93de94543a75dbceebd4fe87b8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61626576616e6174696f6e2f726576657273696679)](https://camo.githubusercontent.com/98378bf18668b5ce54ebdb89e0b1ce6d84208f93de94543a75dbceebd4fe87b8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61626576616e6174696f6e2f726576657273696679)

**Reversify** is a Laravel package designed to reverse engineer your existing database schema to create fully functional migrations, models, controllers that include relationships, traits, attributes, and more. It simplifies the process of reverse-engineering your database into Laravel components, making it ideal for legacy systems or rapid development.

---

Features
--------

[](#features)

- **Migrations**: Generate Laravel migrations from your database schema, including foreign keys and constraints.
- **Models**: Create Eloquent models with support for:
    - Traits
    - Fillable, guarded, casts, with, and hidden attributes
    - Relationships (e.g., `belongsTo`, `hasMany`, etc.)
    - Lifecycle hooks (`creating`, `updating`, etc.)
- **Controllers**: Generate CRUD resource controllers for your database tables.
- **Dynamic Configuration**: Fully configurable to suit your project's needs.

---

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

[](#installation)

1. Require the package via Composer:

    ```
    composer require abevanation/reversify
    ```
2. Publish the configuration file:

    ```
    php artisan vendor:publish --tag=reversify-config
    ```

    This will create a `config/reversify.php` file where you can customize the package behavior.
3. Add the `ReversifyBlueprintMacroServiceProvider` to your `bootstrap/providers.php` (Laravel 11) or `config/app.php` (Laravel 10 or earlier) if it isn't already registered:

    ```
    App\Providers\ReversifyBlueprintMacroServiceProvider::class,
    ```

---

Configuration
-------------

[](#configuration)

The configuration file (`config/reversify.php`) allows you to customize how the package generates migrations, models, and controllers.

### Example Configuration

[](#example-configuration)

```
return [
    'ignore_tables' => ['migrations', 'failed_jobs'], // Tables to ignore during generation

    'models' => [
        'traits' => [
            'users' => ['Illuminate\Database\Eloquent\Factories\HasFactory', 'App\Traits\Loggable'],
            'App\Traits\SoftDeletes',
        ],
        'fillable' => [
            'users' => ['name', 'email', 'password'],
        ],
        'guarded' => ['created_by', 'updated_by'],
        'casts' => [
            'created_at' => 'datetime',
            'updated_at' => 'datetime',
        ],
        'with' => [
            'users' => ['profile'],
        ],
        'hidden' => [
            'users' => ['password', '*token'],
        ],
        'relationships' => [
            'users' => [
                'belongsTo' => ['App\Models\Organization', 'organization', 'organization_id', 'id'],
                'hasMany' => ['App\Models\Policy', 'policies', 'id', 'user_id'],
            ],
        ],
        'lifecycle_hooks' => [
            'users' => [
                'creating' => 'function ($model) {
                    $model->created_by = auth()->id();
                    $model->created_at = now();
                }',
                'updating' => 'function ($model) {
                    $model->updated_by = auth()->id();
                }',
            ],
        ],
    ],
];
```

---

Commands
--------

[](#commands)

### Generate Migrations

[](#generate-migrations)

```
php artisan reversify:migrations
```

- Scans the database schema and generates migration files for each table.
- A separate migration file is created to add foreign key constraints.

### Generate Models

[](#generate-models)

```
php artisan reversify:models
```

- Creates Eloquent models for all tables (except ignored ones).
- Includes configurable attributes like `fillable`, `guarded`, `casts`, `relationships`, and `lifecycle hooks`.

### Generate Controllers

[](#generate-controllers)

```
php artisan reversify:controllers
```

- Generates basic CRUD resource controllers for each table.
- Controllers are placed in the `app/Http/Controllers` directory.

### Generate All Components

[](#generate-all-components)

```
php artisan reversify:generate
```

- Runs `reversify:migrations`, `reversify:models`, and `reversify:controllers` sequentially.

---

Output Examples
---------------

[](#output-examples)

### Migration File

[](#migration-file)

For a table named `users`:

```
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->timestamps();
            $table->softDeletes();
        });
    }

    public function down()
    {
        Schema::dropIfExists('users');
    }
};
```

### Model File

[](#model-file)

For a table named `users`:

```
