In web applications like Laravel, when you want to make changes to the code or database, you'll want to enable a maintenance mode to prevent users from accessing the service, using the maintenance state or “Maintenance Mode” effectively. In this state, the site is temporarily inaccessible to external users, and a message is displayed to them indicating that the site is under maintenance and will be back shortly. This method not only allows the development team to easily implement necessary changes but also preserves the user experience during such modifications.
To activate the maintenance mode in Laravel, simply run the following command in the terminal:
php artisan down
When this command is executed, Laravel automatically brings the site into maintenance mode, and a default message will be shown stating “We are currently performing maintenance on the site, please check back later.”
Restoring the site to normal operation is very simple. Just execute the command below in the terminal, and the site will return to its normal state, allowing users to access the service again:
php artisan up
Other scenarios that you can configure during maintenance mode include displaying custom messages to users. For example, if you want a custom maintenance message to be shown to users, you can use specific flags like:
php artisan down --message="We will be back shortly!"
This command will present a message that you defined to the users while the site is in maintenance mode.
Now, let's run through the command line:
php artisan down
This command is a simple way to activate maintenance mode in Laravel.
php artisan up
This command is used to exit maintenance mode and revert the application back to normal use.
php artisan down --message="We will be back shortly!"
This command is similar to the previous one, but now you can customize a maintenance message that will be shown to your users.