PHPackages                             vicgutt/laravel-inspect-db - 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. vicgutt/laravel-inspect-db

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

vicgutt/laravel-inspect-db
==========================

Inspect and retrieve information about a given database

v0.1.3(3y ago)11.5k1MITPHPPHP ^8.1

Since Nov 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/VicGUTT/laravel-inspect-db)[ Packagist](https://packagist.org/packages/vicgutt/laravel-inspect-db)[ Docs](https://github.com/vicgutt/laravel-inspect-db)[ RSS](/packages/vicgutt-laravel-inspect-db/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (15)Versions (5)Used By (1)

Inspect and retrieve information about a given database
=======================================================

[](#inspect-and-retrieve-information-about-a-given-database)

[![GitHub Tests Action Status](https://github.com/vicgutt/laravel-inspect-db/actions/workflows/run-tests.yml/badge.svg)](https://github.com/vicgutt/laravel-inspect-db/actions/workflows/run-tests.yml)[![GitHub PHPStan Action Status](https://github.com/vicgutt/laravel-inspect-db/actions/workflows/phpstan.yml/badge.svg)](https://github.com/vicgutt/laravel-inspect-db/actions/workflows/phpstan.yml)[![GitHub Code Style Action Status](https://github.com/vicgutt/laravel-inspect-db/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/vicgutt/laravel-inspect-db/actions/workflows/fix-php-code-style-issues.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/d6a367c1120d238de158dd450dfd2450a56654fc2f5bbe41a140e4354f981645/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766963677574742f6c61726176656c2d696e73706563742d64622e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vicgutt/laravel-inspect-db)[![Total Downloads](https://camo.githubusercontent.com/c398410616ec8951aff076677deaa0e3e9db7c706db592d644e433bc64f51ffd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766963677574742f6c61726176656c2d696e73706563742d64622e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vicgutt/laravel-inspect-db)

---

This package allows you to inspect and retrieve information about your databases. This package has been tested against Sqlite, MySQL and PostgreSQL although others might work as well, if not, let's discuss it.

Here's a quick example:

```
use VicGutt\InspectDb\Inspect;

// On a default Laravel "users" table using the "mysql" connection, running:
Inspect::table($name = 'users', $connectionOrSchemaManagerOrNull = 'mysql')->toArray();

// would return the following:
[
    'name' => 'users',
    'engine' => 'InnoDB',
    'collation' => 'utf8mb4_unicode_ci',
    'charset' => 'utf8mb4',
    'autoincrement' => 1,
    'comment' => '',
    'primaryKey' => [
        'name' => 'PRIMARY',
        'primary' => true,
        'unique' => true,
        // ...
    ],
    'columns' => [
        'id' => [/* ... */],
        'name' => [/* ... */],
        'email' => [/* ... */],
        // ...
    ],
    'indexes' => [/* ... */],
    'foreignKeys' => [],
]
```

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

[](#installation)

You can install the package via composer:

```
composer require vicgutt/laravel-inspect-db
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-inspect-db-config"
```

You can check out what the contents of the published config file will be here: [config/inspect-db.php](/config/inspect-db.php)

Inspect
-------

[](#inspect)

The `VicGutt\InspectDb\Inspect` class is the main entry point of the package. It allows you to retrieve information about tables, a table's columns, it's indexes and foreign keys.

### Retrieving the tables of a given database connection

[](#retrieving-the-tables-of-a-given-database-connection)

```
use VicGutt\InspectDb\Inspect;

// returns an instance of `VicGutt\InspectDb\Collections\Entities\TableCollection`
Inspect::tables();
```

Here, as no database connection was specified, the default configured database connection will be used.

### Retrieving a particular table for a given database connection

[](#retrieving-a-particular-table-for-a-given-database-connection)

```
use VicGutt\InspectDb\Inspect;

// returns an instance of `VicGutt\InspectDb\Entities\Table`
Inspect::table('users');
```

Here, as no database connection was specified as second argument, the default configured database connection will be used.

### Retrieving the columns of a particular table for a given database connection

[](#retrieving-the-columns-of-a-particular-table-for-a-given-database-connection)

```
use VicGutt\InspectDb\Inspect;

// returns an instance of `VicGutt\InspectDb\Collections\Entities\ColumnCollection`
Inspect::columns('users');
```

Here, as no database connection was specified as second argument, the default configured database connection will be used.

### Retrieving the indexes of a particular table for a given database connection

[](#retrieving-the-indexes-of-a-particular-table-for-a-given-database-connection)

```
use VicGutt\InspectDb\Inspect;

// returns an instance of `VicGutt\InspectDb\Collections\Entities\IndexCollection`
Inspect::indexes('users');
```

Here, as no database connection was specified as second argument, the default configured database connection will be used.

### Retrieving the foreign keys of a particular table for a given database connection

[](#retrieving-the-foreign-keys-of-a-particular-table-for-a-given-database-connection)

```
use VicGutt\InspectDb\Inspect;

// returns an instance of `VicGutt\InspectDb\Collections\Entities\ForeignKeyCollection`
Inspect::foreignKeys('users');
```

Here, as no database connection was specified as second argument, the default configured database connection will be used.

### Retrieving a particular column of a particular table for a given database connection

[](#retrieving-a-particular-column-of-a-particular-table-for-a-given-database-connection)

```
use VicGutt\InspectDb\Inspect;

// returns an instance of `VicGutt\InspectDb\Entities\Column` or null
Inspect::column('id', 'users');
```

Here, as no database connection was specified as third argument, the default configured database connection will be used.

### Retrieving a particular index of a particular table for a given database connection

[](#retrieving-a-particular-index-of-a-particular-table-for-a-given-database-connection)

```
use VicGutt\InspectDb\Inspect;

// returns an instance of `VicGutt\InspectDb\Entities\Index` or null
Inspect::index('PRIMARY', 'users');
```

Here, as no database connection was specified as third argument, the default configured database connection will be used.

### Retrieving a particular foreign key of a particular table for a given database connection

[](#retrieving-a-particular-foreign-key-of-a-particular-table-for-a-given-database-connection)

```
use VicGutt\InspectDb\Inspect;

// returns an instance of `VicGutt\InspectDb\Entities\ForeignKey` or null
Inspect::foreignKey('posts_user_id_foreign', 'posts');
```

Here, as no database connection was specified as third argument, the default configured database connection will be used.

Collections
-----------

[](#collections)

The collections provided by this package all extend the abstract `VicGutt\InspectDb\Collections\Entities\EntityCollection` class which itself extends from the default Laravel collection *(`Illuminate\Support\Collection`)*.

The available collections are:

- VicGutt\\InspectDb\\Collections\\Entities\\`TableCollection`
- VicGutt\\InspectDb\\Collections\\Entities\\`ColumnCollection`
- VicGutt\\InspectDb\\Collections\\Entities\\`IndexCollection`
- VicGutt\\InspectDb\\Collections\\Entities\\`ForeignKeyCollection`

The above collections differ slightly from the default Laravel collection and behavior you might be used to. That is, our collections internal items can only ever be an array of the entities they represent. As an example, the `TableCollection` items can only ever be an array of `Table`s.

In usage, this translates to type errors being thrown when some collection methods are used:

```
/**
 * The following will throw a `TypeError` with a message specifying the "$item" given
 * is a string rather than instances of `Doctrine\DBAL\Schema\Table` or `VicGutt\InspectDb\Entities\Table`.
 */
Inspect::tables()->map(fn (Table $table): string => $table->name);
Inspect::tables()->pluck('name');
```

The solution to this is to convert our Collection into a default Laravel collection prior to calling methods which returns new instances of the current collection but with mutated items:

```
/**
 * Now, all is well.
 */
Inspect::tables()->toBase()->map(fn (Table $table): string => $table->name);
Inspect::tables()->toBase()->pluck('name');
```

This behavior, although admittedly surprising, helps guarantee a collection of Xs only ever actually contains Xs.

Entities
--------

[](#entities)

Entities are meant to represent units present in a given database.

The available entities are:

- [VicGutt\\InspectDb\\Entities\\`Table`](/src/Entities/Table.php)
- [VicGutt\\InspectDb\\Entities\\`Column`](/src/Entities/Column.php)
- [VicGutt\\InspectDb\\Entities\\`Index`](/src/Entities/Index.php)
- [VicGutt\\InspectDb\\Entities\\`ForeignKey`](/src/Entities/ForeignKey.php)

Click on any of the listed entities above to learn more about the exposed properties and methods.

---

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

If you're interested in contributing to the project, please read our [contributing docs](https://github.com/vicgutt/laravel-inspect-db/blob/main/.github/CONTRIBUTING.md) **before submitting a pull request**.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Victor GUTT](https://github.com/vicgutt)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~43 days

Total

4

Last Release

1153d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/88ae8f0fc220c28b6b5effd3b319d26ee05cf51066c42d72b606d57dad308ae6?d=identicon)[vicgutt](/maintainers/vicgutt)

---

Top Contributors

[![VicGUTT](https://avatars.githubusercontent.com/u/39224143?v=4)](https://github.com/VicGUTT "VicGUTT (28 commits)")

---

Tags

databaselaravellaraveldatabase

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/vicgutt-laravel-inspect-db/health.svg)

```
[![Health](https://phpackages.com/badges/vicgutt-laravel-inspect-db/health.svg)](https://phpackages.com/packages/vicgutt-laravel-inspect-db)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

163166.8k](/packages/cybercog-laravel-clickhouse)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17649.9k](/packages/lacodix-laravel-model-filter)[giacomomasseron/laravel-models-generator

Generate Laravel models from an existing database

484.2k](/packages/giacomomasseron-laravel-models-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
