Created
November 9, 2019 06:25
-
-
Save isheraz/2bc4c62a7b1f330aeb5e9e26c288063a to your computer and use it in GitHub Desktop.
Install iseed and extends to include all tables when seeding
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 | |
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