diff --git a/Console/Migrations/FreshCommand.php b/Console/Migrations/FreshCommand.php index 41d75ade5..133de41ef 100644 --- a/Console/Migrations/FreshCommand.php +++ b/Console/Migrations/FreshCommand.php @@ -6,6 +6,7 @@ use Illuminate\Console\ConfirmableTrait; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\Events\DatabaseRefreshed; +use Illuminate\Database\Migrations\Migrator; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputOption; @@ -28,6 +29,26 @@ class FreshCommand extends Command */ protected $description = 'Drop all tables and re-run all migrations'; + /** + * The migrator instance. + * + * @var \Illuminate\Database\Migrations\Migrator + */ + protected $migrator; + + /** + * Create a new fresh command instance. + * + * @param \Illuminate\Database\Migrations\Migrator $migrator + * @return void + */ + public function __construct(Migrator $migrator) + { + parent::__construct(); + + $this->migrator = $migrator; + } + /** * Execute the console command. * @@ -41,14 +62,16 @@ public function handle() $database = $this->input->getOption('database'); - $this->newLine(); + if ($this->migrator->repositoryExists()) { + $this->newLine(); - $this->components->task('Dropping all tables', fn () => $this->callSilent('db:wipe', array_filter([ - '--database' => $database, - '--drop-views' => $this->option('drop-views'), - '--drop-types' => $this->option('drop-types'), - '--force' => true, - ])) == 0); + $this->components->task('Dropping all tables', fn () => $this->callSilent('db:wipe', array_filter([ + '--database' => $database, + '--drop-views' => $this->option('drop-views'), + '--drop-types' => $this->option('drop-types'), + '--force' => true, + ])) == 0); + } $this->newLine(); diff --git a/MigrationServiceProvider.php b/MigrationServiceProvider.php index 4dad13838..cab266bb2 100755 --- a/MigrationServiceProvider.php +++ b/MigrationServiceProvider.php @@ -130,7 +130,9 @@ protected function registerMigrateCommand() */ protected function registerMigrateFreshCommand() { - $this->app->singleton(FreshCommand::class); + $this->app->singleton(FreshCommand::class, function ($app) { + return new FreshCommand($app['migrator']); + }); } /**