From 6f1a0ce6fff56c3724ca3a3e79e0e5ea89a39ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Garc=C3=ADa?= Date: Tue, 5 Sep 2017 14:23:51 -0500 Subject: [PATCH] Fix #179 --- src/commands/MakeSeederCommand.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/commands/MakeSeederCommand.php b/src/commands/MakeSeederCommand.php index 1444c82d..7b287a1a 100644 --- a/src/commands/MakeSeederCommand.php +++ b/src/commands/MakeSeederCommand.php @@ -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 { @@ -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', @@ -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; @@ -90,7 +97,7 @@ protected function createSeeder() * * @return string */ - protected function getMigrationPath() + protected function seederPath() { return database_path("seeds/LaratrustSeeder.php"); }