Với project XGallery thường xuyên phải reset data sau khi test một cái gì đó. Mà nhiều thứ phải làm quá … nên build nhanh 1 con clear:all
Artisan::command('clear:all', function () {
array_map('unlink', array_filter((array) glob(storage_path('logs/*.log'))));
$this->comment('Logs have been cleared!');
array_map('unlink', array_filter((array) glob(storage_path('app/*.tmp'))));
$this->comment('Tmp files have been cleared!');
$tableNames = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames();
Schema::disableForeignKeyConstraints();
foreach ($tableNames as $name) {
//if you don't want to truncate migrations
if ($name == 'migrations') {
continue;
}
DB::table($name)->truncate();
$this->comment('Table ' . $name . ' is truncated');
}
Schema::enableForeignKeyConstraints();
Artisan::call('config:clear');
Artisan::call('event:clear');
Artisan::call('optimize:clear');
Artisan::call('route:clear');
Artisan::call('view:clear');
$this->comment('Cleared all Laravel cache types. Except cache type');
})->describe('Clear log files & truncate tables');
Leave a Reply