Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function tables($connection = null)
  2. {
  3. return collect(json_decode(json_encode(DB::connection($connection)->select(get_show_tables_query($connection))), true))
  4. ->map(function ($item) {
  5. return array_values($item)[0];
  6. });
  7. }
  8.  
  9. function get_show_tables_query($connection = null)
  10. {
  11. $queryGrammar = DB::connection($connection)->getQueryGrammar();
  12.  
  13. if ($queryGrammar instanceof Illuminate\Database\Query\Grammars\MySqlGrammar) {
  14. return 'SHOW TABLES';
  15. } elseif ($queryGrammar instanceof Illuminate\Database\Query\Grammars\PostgresGrammar) {
  16. return sprintf(
  17. "SELECT table_name FROM information_schema.tables where table_schema = '%s' ORDER BY table_schema,table_name;",
  18. DB::connection($connection)->getConfig('schema') ?: 'public'
  19. );
  20. } elseif ($queryGrammar instanceof Illuminate\Database\Query\Grammars\SQLiteGrammar) {
  21. return "SELECT name FROM sqlite_master WHERE type='table';";
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement