{"id":18500039,"url":"https://github.com/vicgutt/laravel-inspect-db","last_synced_at":"2026-04-17T11:33:56.791Z","repository":{"id":57714402,"uuid":"527309402","full_name":"VicGUTT/laravel-inspect-db","owner":"VicGUTT","description":"Inspect and retrieve information about a given database","archived":false,"fork":false,"pushed_at":"2023-03-16T18:17:46.000Z","size":227,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T05:08:19.189Z","etag":null,"topics":["database","laravel"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VicGUTT.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-21T19:40:54.000Z","updated_at":"2024-02-07T17:29:18.000Z","dependencies_parsed_at":"2024-11-06T13:49:36.772Z","dependency_job_id":"c6e14094-20d3-4276-ac87-f101528e0fa0","html_url":"https://github.com/VicGUTT/laravel-inspect-db","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0714285714285714,"last_synced_commit":"3b0966e1f717a8ebf46a1db8ce9de19000be3dcb"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VicGUTT%2Flaravel-inspect-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VicGUTT%2Flaravel-inspect-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VicGUTT%2Flaravel-inspect-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VicGUTT%2Flaravel-inspect-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VicGUTT","download_url":"https://codeload.github.com/VicGUTT/laravel-inspect-db/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254084858,"owners_count":22011957,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","laravel"],"created_at":"2024-11-06T13:48:14.775Z","updated_at":"2026-04-17T11:33:56.746Z","avatar_url":"https://github.com/VicGUTT.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Inspect and retrieve information about a given database\n\n[![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)\n[![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)\n[![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)\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/vicgutt/laravel-inspect-db.svg?style=flat-square)](https://packagist.org/packages/vicgutt/laravel-inspect-db)\n[![Total Downloads](https://img.shields.io/packagist/dt/vicgutt/laravel-inspect-db.svg?style=flat-square)](https://packagist.org/packages/vicgutt/laravel-inspect-db)\n\n---\n\nThis 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.\n\nHere's a quick example:\n\n```php\nuse VicGutt\\InspectDb\\Inspect;\n\n// On a default Laravel \"users\" table using the \"mysql\" connection, running:\nInspect::table($name = 'users', $connectionOrSchemaManagerOrNull = 'mysql')-\u003etoArray();\n\n// would return the following:\n[\n    'name' =\u003e 'users',\n    'engine' =\u003e 'InnoDB',\n    'collation' =\u003e 'utf8mb4_unicode_ci',\n    'charset' =\u003e 'utf8mb4',\n    'autoincrement' =\u003e 1,\n    'comment' =\u003e '',\n    'primaryKey' =\u003e [\n        'name' =\u003e 'PRIMARY',\n        'primary' =\u003e true,\n        'unique' =\u003e true,\n        // ...\n    ],\n    'columns' =\u003e [\n        'id' =\u003e [/* ... */],\n        'name' =\u003e [/* ... */],\n        'email' =\u003e [/* ... */],\n        // ...\n    ],\n    'indexes' =\u003e [/* ... */],\n    'foreignKeys' =\u003e [],\n]\n```\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require vicgutt/laravel-inspect-db\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"laravel-inspect-db-config\"\n```\n\nYou can check out what the contents of the published config file will be here: [config/inspect-db.php](/config/inspect-db.php)\n\n## Inspect\n\nThe `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.\n\n### Retrieving the tables of a given database connection\n\n```php\nuse VicGutt\\InspectDb\\Inspect;\n\n// returns an instance of `VicGutt\\InspectDb\\Collections\\Entities\\TableCollection`\nInspect::tables();\n```\n\nHere, as no database connection was specified, the default configured database connection will be used.\n\n### Retrieving a particular table for a given database connection\n\n```php\nuse VicGutt\\InspectDb\\Inspect;\n\n// returns an instance of `VicGutt\\InspectDb\\Entities\\Table`\nInspect::table('users');\n```\n\nHere, as no database connection was specified as second argument, the default configured database connection will be used.\n\n### Retrieving the columns of a particular table for a given database connection\n\n```php\nuse VicGutt\\InspectDb\\Inspect;\n\n// returns an instance of `VicGutt\\InspectDb\\Collections\\Entities\\ColumnCollection`\nInspect::columns('users');\n```\n\nHere, as no database connection was specified as second argument, the default configured database connection will be used.\n\n### Retrieving the indexes of a particular table for a given database connection\n\n```php\nuse VicGutt\\InspectDb\\Inspect;\n\n// returns an instance of `VicGutt\\InspectDb\\Collections\\Entities\\IndexCollection`\nInspect::indexes('users');\n```\n\nHere, as no database connection was specified as second argument, the default configured database connection will be used.\n\n### Retrieving the foreign keys of a particular table for a given database connection\n\n```php\nuse VicGutt\\InspectDb\\Inspect;\n\n// returns an instance of `VicGutt\\InspectDb\\Collections\\Entities\\ForeignKeyCollection`\nInspect::foreignKeys('users');\n```\n\nHere, as no database connection was specified as second argument, the default configured database connection will be used.\n\n### Retrieving a particular column of a particular table for a given database connection\n\n```php\nuse VicGutt\\InspectDb\\Inspect;\n\n// returns an instance of `VicGutt\\InspectDb\\Entities\\Column` or null\nInspect::column('id', 'users');\n```\n\nHere, as no database connection was specified as third argument, the default configured database connection will be used.\n\n### Retrieving a particular index of a particular table for a given database connection\n\n```php\nuse VicGutt\\InspectDb\\Inspect;\n\n// returns an instance of `VicGutt\\InspectDb\\Entities\\Index` or null\nInspect::index('PRIMARY', 'users');\n```\n\nHere, as no database connection was specified as third argument, the default configured database connection will be used.\n\n### Retrieving a particular foreign key of a particular table for a given database connection\n\n```php\nuse VicGutt\\InspectDb\\Inspect;\n\n// returns an instance of `VicGutt\\InspectDb\\Entities\\ForeignKey` or null\nInspect::foreignKey('posts_user_id_foreign', 'posts');\n```\n\nHere, as no database connection was specified as third argument, the default configured database connection will be used.\n\n## Collections\n\nThe 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`)_.\n\nThe available collections are:\n\n-   VicGutt\\InspectDb\\Collections\\Entities\\\\`TableCollection`\n-   VicGutt\\InspectDb\\Collections\\Entities\\\\`ColumnCollection`\n-   VicGutt\\InspectDb\\Collections\\Entities\\\\`IndexCollection`\n-   VicGutt\\InspectDb\\Collections\\Entities\\\\`ForeignKeyCollection`\n\nThe 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.\n\nIn usage, this translates to type errors being thrown when some collection methods are used:\n\n```php\n/**\n * The following will throw a `TypeError` with a message specifying the \"$item\" given\n * is a string rather than instances of `Doctrine\\DBAL\\Schema\\Table` or `VicGutt\\InspectDb\\Entities\\Table`.\n */\nInspect::tables()-\u003emap(fn (Table $table): string =\u003e $table-\u003ename);\nInspect::tables()-\u003epluck('name');\n```\n\nThe 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:\n\n```php\n/**\n * Now, all is well.\n */\nInspect::tables()-\u003etoBase()-\u003emap(fn (Table $table): string =\u003e $table-\u003ename);\nInspect::tables()-\u003etoBase()-\u003epluck('name');\n```\n\nThis behavior, although admittedly surprising, helps guarantee a collection of Xs only ever actually contains Xs.\n\n## Entities\n\nEntities are meant to represent units present in a given database.\n\n\u003c!-- or the database itself (--\\\u003e for when we can do Inspect::database(...)) --\u003e\n\nThe available entities are:\n\n-   [VicGutt\\InspectDb\\Entities\\\\`Table`](/src/Entities/Table.php)\n-   [VicGutt\\InspectDb\\Entities\\\\`Column`](/src/Entities/Column.php)\n-   [VicGutt\\InspectDb\\Entities\\\\`Index`](/src/Entities/Index.php)\n-   [VicGutt\\InspectDb\\Entities\\\\`ForeignKey`](/src/Entities/ForeignKey.php)\n\nClick on any of the listed entities above to learn more about the exposed properties and methods.\n\n---\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nIf 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**.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n-   [Victor GUTT](https://github.com/vicgutt)\n-   [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicgutt%2Flaravel-inspect-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvicgutt%2Flaravel-inspect-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicgutt%2Flaravel-inspect-db/lists"}