Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $tableNames = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames();
- foreach ($tableNames as $name) {
- //if you don't want to truncate migrations
- if ($name == 'migrations') {
- continue;
- }
- DB::table($name)->truncate();
- }
- // set tables don't want to trucate here
- $excepts = ['migrations'];
- $tables = DB::connection()
- ->getPdo()
- ->query("SHOW FULL TABLES")
- ->fetchAll();
- $tableNames = [];
- $keys = array_keys($tables[0]);
- $keyName = $keys[0];
- $keyType = $keys[1];
- foreach ($tableNames as $name) {
- //if you don't want to truncate migrations
- if (in_array($name[$keyName], $excepts))
- continue;
- // truncate tables only
- if('BASE TABLE' !== $name[$keyType])
- continue;
- DB::table($name)->truncate();
- }
- DB::statement("SET foreign_key_checks=0");
- $databaseName = DB::getDatabaseName();
- $tables = DB::select("SELECT * FROM information_schema.tables WHERE table_schema = '$databaseName'");
- foreach ($tables as $table) {
- $name = $table->TABLE_NAME;
- //if you don't want to truncate migrations
- if ($name == 'migrations') {
- continue;
- }
- DB::table($name)->truncate();
- }
- DB::statement("SET foreign_key_checks=1");
- // Get db name
- $db = DB::connection()->getDatabaseName();;
- // Delete db
- DB::statement('DROP DATABASE `'.$db.'`');
- // Create db
- DB::statement('CREATE DATABASE `'.$db.'`');
Add Comment
Please, Sign In to add comment