PHP code example of vicgutt / laravel-inspect-db

1. Go to this page and download the library: Download vicgutt/laravel-inspect-db library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vicgutt / laravel-inspect-db example snippets


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' => [],
]

use VicGutt\InspectDb\Inspect;

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

use VicGutt\InspectDb\Inspect;

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

use VicGutt\InspectDb\Inspect;

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

use VicGutt\InspectDb\Inspect;

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

use VicGutt\InspectDb\Inspect;

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

use VicGutt\InspectDb\Inspect;

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

use VicGutt\InspectDb\Inspect;

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

use VicGutt\InspectDb\Inspect;

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

/**
 * 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');

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