Search code examples
sqlitelaravellaravel-artisan

Laravel - PHP Artisan Tinker: How to view all tables in sqlite database


I have a Laravel project and I have a sqlite database. I want to view all the tables in the database in php artisan tinker.

I have tried this $tables = DB::select('SHOW TABLES'); but it throws this error Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 1 near "SHOW": syntax error (SQL: SHOW TABLES)'


Solution

  • Here is the answer, and it can be found here, https://www.sqlite.org/faq.html#q7

    DB::select("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;")
    

    Thanks to @GwynBleidd on Laracasts for finding the answer.