Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zeroinf's avatar

List all Table in Database

Hi there ! Im verry beginer with laravel , i have a simply question . Playing with Laravel 6.2 i want to list all tables from conected database in my dashboard . i serched in web but for me is everiting confusional . I kindly ask you if you can help me by indicating the code to insert in the dashboard. Please don't get upset about my stupid request. Thank you for your pasience . Here is my code (Dashboard )

@extends('layouts.app') @section('content')

Dashboard
            <div class="card-body">
                @if (session('status'))
                    <div class="alert alert-success" role="alert">
                        {{ session('status') }}
                    </div>
                @endif
            <!-- List all table from database -->

             
            </div>
        </div>
    </div>
</div>
@endsection
0 likes
4 replies
Sinnbeck's avatar

you should be able to do something like this in your controller

$tables = DB::select('SHOW TABLES');

And in your blade file

@foreach($tables as $table)
      {{ $table->Tables_in_db_name }}
@endforeach
zeroinf's avatar

Verry fast response , but i recivied a error (Symfony\Component\Debug\Exception\FatalThrowableError Class 'App\Http\Controllers\DB' not found ) . I dont know how to resolve this . I put home.blade code & HomeController code under

@extends('layouts.app') @section('content') Dashboard
            <div class="card-body">
                @if (session('status'))
                    <div class="alert alert-success" role="alert">
                        {{ session('status') }}
                    </div>
                @endif
            <!-- List all table from database -->
           
                foreach ($tables as $table) {
                foreach ($table as $key => $value)
                    echo $value;
                }
                  
            </div>
        </div>
    </div>
</div>
@endsection
Sinnbeck's avatar

In the very top of the controller (look for use) you should add

use DB;
1 like

Please or to participate in this conversation.