Laravel
227
w3alert.com
04-01-2020
Laravel Application Configuration Tutorial. In this tutorial, you will learn how to configure the laravel applications.
In the previous tutorial, you have known about the laravel config directory. This directory holds all the configuration files of our web applications. The config directory holds sub config directories such as database, mailing, services, auth, cache and session, etc.
The configuration of the Laravel web application allows you to define the configuration per environment. Here, you will learn about various configurations in laravel web applications and how you can do basic configuration in these applications.
You can configure the Environment variables in .evn file. You find this file from your laravel application root directory. In this file you can set / configure database details, app mode detail like production / test, set mail smtp details etc.
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel_application_configuration DB_USERNAME=root DB_PASSWORD=root MAIL_DRIVER=smtp MAIL_HOST=smtp.mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null
If you want to access environment variables from anywhere in your laravel web application. You can access or get like below:
'env' => env('APP_NAME', 'laravel'),
In this file, You can also configure or set multiple database connections. So go to config/database.php set database credentials like this below:
'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'prefix_indexes' => true, 'strict' => true, 'engine' => null, ],
Whatever be the web application, everyone wants this. The application loads fast and the application does not take much time to load. So to speed up your larval web application, you should cache all your configuration files into one file using the configuration using the cache artisan command. This will merge all the configuration options of your larva web application into a special file that will be loaded quickly by the framework.
You should usually run the php artisan config:cache command as part of your production deployment routine.
Whenever you need to put your Laravel web application in maintenance mode. So you can use the below command to handle the application in down and up mode.
To enable the laravel application maintenance mode by the following command −
php artisan down
To disable the laravel application maintenance mode by the following command −
php artisan up