Skip to content

Instantly share code, notes, and snippets.

@isheraz
Created November 9, 2019 06:25
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 isheraz/2bc4c62a7b1f330aeb5e9e26c288063a to your computer and use it in GitHub Desktop.
Save isheraz/2bc4c62a7b1f330aeb5e9e26c288063a to your computer and use it in GitHub Desktop.
Install iseed and extends to include all tables when seeding
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class iseedAll extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'iseed:all';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command plugin for iseed to seed all databases except migrations table';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$dbName = env('DB_DATABASE');
$query = \DB::select("SHOW TABLES WHERE 'Tables_in_$dbName' NOT LIKE 'migrations'");
$collection = new \Illuminate\Support\Collection($query);
$tables = "";
$collectionArray = $collection->toArray();
$iteration = 0;
foreach($collectionArray as $item){
if( $iteration < (sizeof($collectionArray) - 2) ){
$tables .= array_values( (array) $item)[0].",";
}else{
$tables .= array_values( (array) $item)[0];
}
$iteration++;
}
$this->info('Calling iseed for all tables except migrations ...');
$this->call('iseed', ["tables" => $tables]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment