UpCommand.php
TLDR
This file contains the UpCommand
class, which is a Laravel console command used to bring the application out of maintenance mode.
Methods
handle()
Executes the console command. It checks if the maintenance mode is active; if not, it displays a message and returns 0. If the maintenance mode is active, it deactivates it, removes the maintenance.php
file from the storage folder, dispatches the MaintenanceModeDisabled
event, and displays a success message. If an exception occurs during the process, it displays an error message with the exception message and returns 1.
Classes
UpCommand
The UpCommand
class extends the Command
class provided by Laravel. It represents the console command used to bring the application out of maintenance mode. It has the following properties:
-
$name
: The console command name, set to 'up'. -
$description
: The console command description, set to 'Bring the application out of maintenance mode'.
<?php
namespace Illuminate\Foundation\Console;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Foundation\Events\MaintenanceModeDisabled;
use Symfony\Component\Console\Attribute\AsCommand;
#[AsCommand(name: 'up')]
class UpCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'up';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Bring the application out of maintenance mode';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
try {
if (! $this->laravel->maintenanceMode()->active()) {
$this->components->info('Application is already up.');
return 0;
}
$this->laravel->maintenanceMode()->deactivate();
if (is_file(storage_path('framework/maintenance.php'))) {
unlink(storage_path('framework/maintenance.php'));
}
$this->laravel->get('events')->dispatch(new MaintenanceModeDisabled());
$this->components->info('Application is now live.');
} catch (Exception $e) {
$this->components->error(sprintf(
'Failed to disable maintenance mode: %s.',
$e->getMessage(),
));
return 1;
}
return 0;
}
}