Skip to main content

Laravel – Configuration

Laravel – Configuration

In the previous chapter, we have seen that the basic configuration files of Laravel are included in the config directory. In this chapter, let us discuss the categories included in the configuration.

Environment Configuration

Environment variables are those which provide a list of web services to your web application. All the environment variables are declared in the .env file which includes the parameters required for initializing the configuration.
By default, the .env file includes the following parameters −

Important Points

While working with basic configuration files of Laravel, the following points are to be noted −
  • The .env file should not be committed to the application source control, since each developer or user has some predefined environment configuration for the web application.
  • For backup options, the development team should include the .env.example file, which should contain the default configuration.

Retrieval of Environment Variables

All the environment variables declared in the .env file can be accessed by env-helper functions which will call the respective parameter. These variables are also listed into $_ENV global variable whenever the application receives a request from the user end. You can access the environment variable as shown below −
env-helper functions are called in the app.php file included in the config folder. The above-given example is calling for the basic local parameter.

Accessing Configuration Values

You can easily access the configuration values anywhere in the application using the global config helper function. In case if the configuration values are not initialized, default values are returned.
For example, to set the default time zone, the following code is used −

Caching of Configuration

To increase the performance and to boost the web application, it is important to cache all the configuration values. The command for caching the configuration values is −
The following screenshot shows caching in a systematic approach −
php_artisian_down
php_artisian_down

Maintenance Mode

Sometimes you may need to update some configuration values or perform maintenance on your website. In such cases, keeping it in maintenance mode, makes it easier for you. Such web applications which are kept in maintenance mode, throw an exception namely MaintenanceModeException with a status code of 503.
You can enable the maintenance mode on your Laravel web application using the following command −
php_artisian_down
php_artisian_down
The following screenshot shows how the web application looks when it is down
start_maintenance_mode
start_maintenance_mode
Once you finish working on updates and other maintenance, you can disable the maintenance mode on your web application using following command −
Now, you can find that the website shows the output with proper functioning and depicting that the maintenance mode is now removed as shown below −
Laravel Online Tutorial
Laravel Online Tutorial

Popular posts from this blog

What is Lumen?

What is Lumen? Lumen  is PHP micro-framework that built on Laravel’s top components.It is created by Taylor Otwell. It is perfect option for building Laravel based micro-services and fast REST API’s. It’s one of the fastest micro-frameworks available. You can install Lumen using composer by running below command 1 composer create - project -- prefer - dist laravel / lumen blog

Laravel – Response

Laravel – Response A web application responds to a user’s request in many ways depending on many parameters. This chapter explains you in detail about responses in Laravel web applications. Basic Response Laravel provides several different ways to return response. Response can be sent either from route or from controller. The basic response that can be sent is simple string as shown in the below sample code. This string will be automatically converted to appropriate HTTP response. Example Step 1  − Add the following code to  app/Http/routes.php  file. app/Http/routes.php 1 2 3 Route :: get ( '/basic_response' , function ( ) {    return 'Hello World' ; } ) ; Step 2  −  Visit  the following URL to test the basic response. 1 http : //localhost:8000/basic_response Step 3  − The output will appear as shown in the following image. Attaching Headers The response can be attached t...

Which template engine Laravel use ?

Which template engine Laravel use ? Laravel uses Blade Templating Engine. Blade is the simple, yet powerful templating engine provided with Laravel. Unlike other popular PHP templating engines, Blade does not restrict you from using plain PHP code in your views. In fact, all Blade views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application. Blade view files use the .blade.php file extension and are typically stored in the resources/views directory.