Skip to content

Instantly share code, notes, and snippets.

@edi9999
Created April 28, 2014 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edi9999/11367676 to your computer and use it in GitHub Desktop.
Save edi9999/11367676 to your computer and use it in GitHub Desktop.
Flush the database with Laravel
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class CreateNewDatabase extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'db:new';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Cleans up the database';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$this->line('Set keycheck=0');
DB::statement('SET FOREIGN_KEY_CHECKS=0');
$tables= DB::select('SHOW TABLES;');
$this->line('removing tables');
foreach ($tables as $table) {
foreach ($table as $key=>$tableName) {
$tables= DB::statement("DROP TABLE $tableName;");
}
}
$this->line('tables removed');
DB::statement('SET FOREIGN_KEY_CHECKS=1');
$this->line('Set keycheck=1');
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment