diff --git a/src/Illuminate/Database/Console/Migrations/StatusCommand.php b/src/Illuminate/Database/Console/Migrations/StatusCommand.php index 9c4513b37716..8b8131dd2757 100644 --- a/src/Illuminate/Database/Console/Migrations/StatusCommand.php +++ b/src/Illuminate/Database/Console/Migrations/StatusCommand.php @@ -63,7 +63,7 @@ public function handle() $batches = $this->migrator->getRepository()->getMigrationBatches(); $migrations = $this->getStatusFor($ran, $batches) - ->when($this->option('pending'), fn ($collection) => $collection->filter(function ($migration) { + ->when($this->option('pending') !== false, fn ($collection) => $collection->filter(function ($migration) { return str($migration[1])->contains('Pending'); })); @@ -78,11 +78,15 @@ public function handle() ); $this->newLine(); - } elseif ($this->option('pending')) { + } elseif ($this->option('pending') !== false) { $this->components->info('No pending migrations'); } else { $this->components->info('No migrations found'); } + + if ($this->option('pending') && $migrations->some(fn ($m) => str($m[1])->contains('Pending'))) { + return $this->option('pending'); + } }); } @@ -130,7 +134,7 @@ protected function getOptions() { return [ ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], - ['pending', null, InputOption::VALUE_NONE, 'Only list pending migrations'], + ['pending', null, InputOption::VALUE_OPTIONAL, 'Only list pending migrations', false], ['path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the migrations files to use'], ['realpath', null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'], ];