How to Get Config Variable Value in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Order By Multiple Columns Example
- How to Create Model in Laravel using Command?
- How to Add Google Map in Laravel?
- How to Install Laravel in Ubuntu Server?
- Laravel Sweet Alert Confirm Delete Example
- Laravel Add Custom Configuration File Example
- How to Add Foreign Key in Laravel Migration?
- Laravel Livewire Delete Confirmation Example
- Laravel Model Events Tutorial
- How to Set Config Value Dynamically in Laravel?
- Laravel Redirect Back to Previous Page After Login Example
- How to Get Query Log in Laravel Eloquent?