Skip to content

Instantly share code, notes, and snippets.

@lozadaOmr
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save lozadaOmr/f2939b4efb1e0c814bc7 to your computer and use it in GitHub Desktop.

Select an option

Save lozadaOmr/f2939b4efb1e0c814bc7 to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class DropTables extends Command {

	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = &#039;migrate:clear&#039;;

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = &#039;Clears all the tables.&#039;;

	/**
	 * Create a new command instance.
	 *
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function fire()
	{
		$tables = [];

		DB::statement( &#039;SET FOREIGN_KEY_CHECKS=0&#039; );

		foreach (DB::select(&#039;SHOW TABLES&#039;) as $k =&gt; $v) {
			$tables[] = array_values((array)$v)[0];
		}

		foreach($tables as $table) {
			Schema::drop($table);
			echo &quot;Table &quot;.$table.&quot; has been dropped.&quot;.PHP_EOL;
		}

	}

}

Laravel Snippet by - John Dave Decano

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment