PHPackages                             zuqongtech/laravel-db-introspection - 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. zuqongtech/laravel-db-introspection

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

zuqongtech/laravel-db-introspection
===================================

A Laravel package for automatic database introspection and model generation supporting MySQL, PostgreSQL, SQL Server, and more.

v1.0.6(3w ago)1106MITPHPPHP ^8.2CI failing

Since Nov 12Pushed 3w agoCompare

[ Source](https://github.com/gideonzozingao/laravel-db-introspection)[ Packagist](https://packagist.org/packages/zuqongtech/laravel-db-introspection)[ RSS](/packages/zuqongtech-laravel-db-introspection/feed)WikiDiscussions dev Synced today

READMEChangelog (1)Dependencies (15)Versions (11)Used By (0)

Laravel DB Introspection
========================

[](#laravel-db-introspection)

[![Packagist Version](https://camo.githubusercontent.com/ee92c05368388d8ca79d2be4cca6d66cbd0c5e53affcab23e1c2b413f96b033b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a75716f6e67746563682f6c61726176656c2d64622d696e74726f7370656374696f6e2e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/zuqongtech/laravel-db-introspection)[![License](https://camo.githubusercontent.com/37e87851b1f8d3ed802484d99506b64290d4caab17055b02845d4103ba7d7296/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f676964656f6e7a6f7a696e67616f2f6c61726176656c2d64622d696e74726f7370656374696f6e2e7376673f7374796c653d666f722d7468652d6261646765)](LICENSE)[![Build Status](https://camo.githubusercontent.com/c495d52fad35466e74fd2756af3f372e3e8c0f6a148c2436eb87cd190a6984c4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a75716f6e67746563682f6c61726176656c2d64622d696e74726f7370656374696f6e2f74657374732e796d6c3f7374796c653d666f722d7468652d6261646765)](https://github.com/gideonzozingao/laravel-db-introspection/actions)[![Laravel](https://camo.githubusercontent.com/9b55783b5ef75fbb4fa0953845a418da290736f80131ecb4de0a875446bb91cc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302e7825323025374325323031312e782d4646324432303f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)](https://laravel.com)[![PHP](https://camo.githubusercontent.com/d42f00a0774ba79b377dcc0373c3862649590e18801c3f009c6a5c2c83dd3db7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e322d626c75653f7374796c653d666f722d7468652d6261646765266c6f676f3d706870)](https://www.php.net)

> A Laravel package for automatic database introspection, model discovery, constraint analysis, and Eloquent model generation. Scans your connected database, analyzes schema metadata, and generates robust Eloquent models — complete with relationships, indexes, PHPDoc, and constraints.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Dependencies](#dependencies)
- [Laravel 12 Compatibility](#laravel-12-compatibility)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Basic Usage](#basic-usage)
    - [Available Flags](#available-flags)
    - [Example Commands](#example-commands)
- [Generated Output](#generated-output)
- [Development](#development)
- [Contributing](#contributing)
- [Credits](#credits)

---

Features
--------

[](#features)

CategoryCapability**Database Support**Multi-engine support (MySQL, PostgreSQL, SQLite, SQL Server)**Model Generation**Auto-generates Eloquent models from live schema**Relationships**FK-based detection with optional inverse relationships**Schema Analysis**Constraint, index, and integrity analysis**Developer Experience**Full PHPDoc generation, dry-run preview, model backups**Configurability**Custom paths, namespaces, table filters, and connections---

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

[](#requirements)

- PHP `^8.2`
- Laravel `10.x` or `11.x`
- Composer `2.x`

---

Dependencies
------------

[](#dependencies)

The following locked versions are used in this package. All runtime dependencies carry an MIT license unless noted.

**Runtime**

PackageVersionPurpose`laravel/framework``v11.46.1`Core Laravel framework`nesbot/carbon``3.10.3`Date/time handling`doctrine/inflector``2.1.0`String inflection for model naming`guzzlehttp/guzzle``7.10.0`HTTP client`monolog/monolog``3.9.0`Logging`ramsey/uuid``4.9.1`UUID generation`league/flysystem``3.30.2`Filesystem abstraction`vlucas/phpdotenv``v5.6.2`Environment variable loading`symfony/console``v7.3.6`CLI command infrastructure`brick/math``0.14.0`Arbitrary-precision arithmetic**Development**

PackageVersionPurpose`phpunit/phpunit``11.5.44`Test runner`orchestra/testbench``v9.15.0`Laravel package testing harness`mockery/mockery``1.6.12`Mock object framework`fakerphp/faker``v1.24.1`Fake data generation for tests`laravel/pint``v1.27.0`PHP code style fixer`nunomaduro/collision``v8.8.2`CLI error reporting`laravel/tinker``v2.10.1`Interactive REPL---

Laravel 12 Compatibility
------------------------

[](#laravel-12-compatibility)

This package supports both **Laravel 11** and **Laravel 12** from the same codebase. No breaking changes are required in your application — only the dependency constraints need updating.

### What changed in Laravel 12 that affects this package

[](#what-changed-in-laravel-12-that-affects-this-package)

**`Schema::getTableListing()` now returns schema-qualified names**

In Laravel 12, `Schema::getTableListing()` returns table names prefixed with the schema name by default (e.g. `main.users` instead of `users`). If the package calls this method internally to discover tables, you must strip the schema prefix or pass `schemaQualified: false`:

```
// Laravel 11 behaviour (unqualified)
Schema::getTableListing();
// ['migrations', 'users', 'orders']

// Laravel 12 default (qualified)
Schema::getTableListing();
// ['main.migrations', 'main.users', 'main.orders']

// Laravel 12 — opt out of qualification to restore old behaviour
Schema::getTableListing(schemaQualified: false);
// ['migrations', 'users', 'orders']
```

**`Grammar` and `Blueprint` constructor signatures changed**

Laravel 12 requires a `Connection` instance to be passed to `Illuminate\Database\Grammar` and `Illuminate\Database\Schema\Blueprint` constructors. The old `setConnection()` method has been removed. If the package instantiates either class directly, update the call:

```
// Laravel 11
$grammar = new MySqlGrammar;
$grammar->setConnection($connection);

// Laravel 12+
$grammar = new MySqlGrammar($connection);
```

**Carbon 2.x support removed**

Laravel 12 drops Carbon 2. This package's lock file already uses Carbon `3.10.3`, so no action is needed.

**`HasUuids` now generates UUIDv7**

The `HasUuids` trait switched from UUIDv4 to UUIDv7. This only matters if you rely on UUID ordering in generated models. No change is required for the generator itself.

---

### Upgrading the package to support Laravel 12

[](#upgrading-the-package-to-support-laravel-12)

**1. Update `composer.json` constraints**

```
{
    "require": {
        "php": "^8.2",
        "laravel/framework": "^11.0|^12.0"
    },
    "require-dev": {
        "orchestra/testbench": "^9.0|^10.0",
        "phpunit/phpunit": "^11.0|^12.0",
        "pestphp/pest": "^2.0|^3.0"
    }
}
```

**2. Expand the CI matrix**

Add Laravel 12 alongside Laravel 11 in your GitHub Actions workflow:

```
# .github/workflows/tests.yml
strategy:
  matrix:
    php: [8.2, 8.3, 8.4]
    laravel: ['11.*', '12.*']
    include:
      - laravel: '11.*'
        testbench: '9.*'
      - laravel: '12.*'
        testbench: '10.*'
    exclude:
      - php: 8.1
        laravel: '11.*'
      - php: 8.1
        laravel: '12.*'
```

**3. Guard schema-qualified table names**

If the package uses `Schema::getTableListing()`, add a version guard to normalise output across both framework versions:

```
use Illuminate\Support\Facades\Schema;

$tables = version_compare(app()->version(), '12.0.0', '>=')
    ? Schema::getTableListing(schemaQualified: false)
    : Schema::getTableListing();
```

**4. Run the full test suite against both versions**

```
# Test against Laravel 11
composer require laravel/framework:^11.0 orchestra/testbench:^9.0 --no-update
composer update && composer test

# Test against Laravel 12
composer require laravel/framework:^12.0 orchestra/testbench:^10.0 --no-update
composer update && composer test
```

### Version support matrix

[](#version-support-matrix)

Package versionLaravel 11Laravel 12PHP`1.x` (current)✅❌`^8.2``2.x` (planned)✅✅`^8.2`> Laravel 11 security support ended March 12, 2026. Laravel 12 receives bug fixes until August 2026 and security fixes until February 2027.

---

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

[](#installation)

Install via Composer:

```
composer require zuqongtech/laravel-db-introspection
```

For local development:

```
git clone https://github.com/zuqongtech/laravel-db-introspection.git
cd laravel-db-introspection
composer install
```

---

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

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish \
  --provider="Zuqongtech\LaravelDbIntrospection\LaravelDbIntrospectionServiceProvider" \
  --tag=config
```

This creates `config/zt-introspection.php`:

```
return [
    'output_path'   => app_path('Models'),
    'namespace'     => 'App\\Models',
    'ignore_tables' => [],
];
```

---

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
php artisan zt:generate-models
```

### Available Flags

[](#available-flags)

#### Model Generation

[](#model-generation)

FlagDescriptionExample`--force`Overwrite existing models without prompting`--force``--backup`Back up existing models before overwriting`--backup``--dry-run`Preview actions without writing any files`--dry-run``--namespace=`Override the namespace for generated models`--namespace="App\\Domain\\Models"``--path=`Override the output directory`--path=modules/Core`#### Table Selection &amp; Filtering

[](#table-selection--filtering)

FlagDescriptionExample`--tables=*`Generate models only for the specified tables`--tables=users --tables=orders``--ignore=*`Exclude specific tables from generation`--ignore=migrations``--connection=`Use a specific database connection`--connection=pgsql`#### Documentation &amp; Metadata

[](#documentation--metadata)

FlagDescriptionExample`--with-phpdoc`Add PHPDoc blocks for IDE autocompletion`--with-phpdoc``--with-constraints`Embed constraint details in model comments`--with-constraints`#### Relationships

[](#relationships)

FlagDescriptionExample`--with-inverse`Generate inverse relations (`hasMany`, `hasOne`)`--with-inverse``--validate-fk`Validate all foreign key references exist`--validate-fk`#### Constraint &amp; Integrity Analysis

[](#constraint--integrity-analysis)

FlagDescriptionExample`--analyze-constraints`Display a summary of PKs, FKs, and indexes`--analyze-constraints``--validate-fk`Validate FK integrity across all tables`--validate-fk``--show-recommendations`Show schema optimization suggestions`--show-recommendations`---

### Example Commands

[](#example-commands)

Generate models with PHPDoc and inverse relationships:

```
php artisan zt:generate-models --with-phpdoc --with-inverse
```

Generate models for specific tables only:

```
php artisan zt:generate-models --tables=users --tables=orders
```

Validate foreign keys and analyze constraints:

```
php artisan zt:generate-models --validate-fk --analyze-constraints
```

Run a full analysis with optimization recommendations:

```
php artisan zt:generate-models --analyze-constraints --show-recommendations
```

Preview what would be generated without writing files:

```
php artisan zt:generate-models --dry-run
```

---

Generated Output
----------------

[](#generated-output)

Models are written to `app/Models/` by default:

```
app/
└── Models/
    ├── User.php
    ├── Order.php
    └── Product.php

```

Each generated model includes:

- `$table` — explicit table binding
- `$fillable` — all column names
- `$primaryKey` — including composite key support
- Soft delete detection (`SoftDeletes` trait)
- Timestamp detection (`$timestamps`)
- Relationships from foreign keys
- Optional inverse relationships
- Optional PHPDoc property blocks
- Optional constraint annotations

**Example generated model:**

```
