Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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