Created
April 28, 2014 10:16
-
-
Save edi9999/11367676 to your computer and use it in GitHub Desktop.
Flush the database with Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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