Is there a way I could truncate all the tables in a db using eloquent or fluent in laravel 4? I do not want to specify table names, I just want to truncate all the tables. In ot
This is how i truncate all tables inside a database (including table exceptions), it works for me.
// 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();
}