I need to list out the tables in database, I found this query
SHOW TABLES LIKE 'merTrans%'
to get the tables but how could I use the foreach
to get the table names in Laravel 5.1?
The syntax is: SELECT column1, column2 FROM table1, table2 WHERE column2='value'; In the above SQL statement: The SELECT clause specifies one or more columns to be retrieved; to specify multiple columns, use a comma and a space between column names.
To list out the tables in database you can do
$tables = DB::select('SHOW TABLES'); foreach($tables as $table) { echo $table->Tables_in_db_name; }
You'll have to change the db_name to the name of your database.
EDIT : FOR LIKE CASES
foreach ($tables as $table) { foreach ($table as $key => $value) echo $value; }
I've been using this:
$tables = DB::connection()->getDoctrineSchemaManager()->listTableNames();
It requires doctrine/dbal as a dependency. But some migration features already need DBAL to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With