How to get all tables lists of database in Laravel 5 ?


Here, we fetch all tables names with prefix from database using laravel DB facade. So if you require to get all tables then you are at right place.

As we can get simply all table lists by following sql query:

SHOW TABLES

In Laravel 5 application we will use same above query by using laravel DB select method. So let's see bellow example:

Example:

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

$tables = array_map('current',$tables);

dd($tables);

Output:

Array

(

[0] => ban

[1] => events

[2] => log_activities

[3] => migrations

[4] => password_resets

[5] => products

[6] => tags

[7] => users

[8] => youtube_access_tokens

)

I hope you found your solution....


July 3, 2017 | 253 Viewer | Category : PHP Laravel
Related Posts:



Blog Search