Laravel create command for get all table of using db

FIrst of all hit below command for create command

php artisan make:command DbInfo

 After save below code into Dbinfo.php  file. Run below command for checking all tables in your db

php artisan command: db-info

<?php


namespace App\Console\Commands;

use Faker\Core\Color;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class DbInfo extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:db-info';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $db_name = config('database.connections.mysql.database');
        $tables = Schema::getAllTables();
        $tables_list ='';
        foreach($tables as $table){
            $tables_list.= $table->Tables_in_libra."\n";
        }
        $total_tbl = count($tables);
        echo "\033[01;31m ====================== Table(\033[01;32m$total_tbl\033[0m \033[01;31m) =============== \033[0m \n";
        echo "\033[01;32m $tables_list \033[0";

        echo "\033[01;31m xxxxxxxxxxxxxxxxxxxxxx All Table List Start xxxxxxxxxxxxxxxxx \033[0m \n";

    }
}

Comments