How to Get Config Variable Value in Laravel?

By Hardik Savani April 16, 2024 Category : Laravel

Hi Artisan,

Now, let's see an example of how to get config value in laravel. In this article, we will implement a how to get value from config file in laravel. This example will help you laravel get config value in controller. I’m going to show you about laravel get config value in blade.

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

Whenever you need to get configuration files value then you can get using config helper in Laravel. If you are working on Laravel then you should use Config facade for get and set value of config file. Maybe sometimes we require to get application url from app.php file or database name from database.php file so you can get this way:

Example:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Config;

class DemoController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index(Request $request)

{

/* Example 1: Get Config Value in Laravel */

$appName = Config::get('app.name');

/* Example 2: Get Config Value in Laravel */

$appName2 = config('app.name');

dd($appName, $appName2);

}

}

I hope it can help you...

Tags :
Shares