Skip to content

Commit c0cbf90

Browse files
committed
Added receiving a list of database tables in the DatabaseTableTrait
1 parent fd92dba commit c0cbf90

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Models/DatabaseTableTrait.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,22 @@ public function table(string $table): Table
3030
}
3131
return $this->tables[$table];
3232
}
33+
34+
/**
35+
* Получение списка таблицы базы данных.
36+
* @param bool перезапросить список таблиц
37+
* @return array
38+
*/
39+
public function tables(bool $reload = false): array
40+
{
41+
static $tables = null;
42+
if (null === $tables || true === $reload) {
43+
$tables = [];
44+
$rows = $this->query('SHOW TABLES')->numericArrayAll();
45+
foreach ($rows as &$row) {
46+
$tables[] = $row[0];
47+
}
48+
}
49+
return $tables;
50+
}
3351
}

0 commit comments

Comments
 (0)