Skip to content

Commit

Permalink
Merge pull request #191 from santigarcor/4.0
Browse files Browse the repository at this point in the history
Fix #179
  • Loading branch information
santigarcor committed Sep 5, 2017
2 parents 1b5b50a + 6f1a0ce commit 35b3ae5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/commands/MakeSeederCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public function handle()
{
$this->laravel->view->addNamespace('laratrust', substr(__DIR__, 0, -8).'views');

if (file_exists($this->seederPath())) {
$this->line('');

$this->warn("The LaratrustSeeder file already exists. Delete the existing one if you want to create a new one.");
$this->line('');
return;
}

if ($this->createSeeder()) {
$this->info("Seeder successfully created!");
} else {
Expand All @@ -65,7 +73,6 @@ protected function createSeeder()
$user = new Collection(Config::get('laratrust.user_models', ['App\User']));
$user = $user->first();

$migrationPath = $this->getMigrationPath();
$output = $this->laravel->view->make('laratrust::generators.seeder')
->with(compact([
'role',
Expand All @@ -76,7 +83,7 @@ protected function createSeeder()
]))
->render();

if (!file_exists($migrationPath) && $fs = fopen($migrationPath, 'x')) {
if ($fs = fopen($this->seederPath(), 'x')) {
fwrite($fs, $output);
fclose($fs);
return true;
Expand All @@ -90,7 +97,7 @@ protected function createSeeder()
*
* @return string
*/
protected function getMigrationPath()
protected function seederPath()
{
return database_path("seeds/LaratrustSeeder.php");
}
Expand Down

0 comments on commit 35b3ae5

Please sign in to comment.