How to add custom config file to app/config in Laravel 5?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Title: Adding Custom Config Files to Laravel App/Config Directory

Introduction: In Laravel, config files are essential for storing application configuration settings. By default, Laravel provides several configuration options within the app/config directory. However, sometimes you might need to add your own custom configuration options to accommodate specific project requirements. This blog post aims to provide a comprehensive guide on how to create and utilize a custom config file in your Laravel 5 project.

Step 1: Define Your Custom Config File
To start, open the existing app/config directory and create a new folder named 'custom_config'. Within this newly created folder, create a PHP file called 'custom_config.php'. This will house all of your custom configuration settings.

Step 2: Establish the Basic Structure
Inside the 'custom_config.php' file, add the following code to set up the basic structure for your custom config file.

php
<?php
return [
    // Add your custom configuration options here
];

Step 3: Define Your Custom Configuration Options
To effectively manage and organize your custom configuration settings, use subarrays within the main array to group related options together. For example:

php
<?php
return [
    'custom_settings' => [
        // Add specific configuration options for your custom section here
        'key1' => 'value1',
        'key2' => 'value2',
        '...',
    ]
];

Step 4: Require the Custom Config File
Now that you have defined your custom config file, you need to make it available for use in your Laravel application. To do this, open the 'app/config/app.php' and add the following code at the bottom of the file. This will load your custom configuration file when the application starts.

php
<?php
// ... Other app config options here...

Config::set('custom_config', require __DIR__ . '/../custom_config/custom_config.php');

Step 5: Access Custom Configuration Options
To use your custom configuration options, you can reference them within any of your application's views or controllers. For example, to access the custom setting with 'key1', you would call:

php
<?php
// View file code: echo Config::get('custom_config.custom_settings.key1');

// Controller code: $value = Config::get('custom_config.custom_settings.key1');

Conclusion:
Creating and utilizing custom config files in Laravel allows you to maintain a clean and organized project structure. By following the steps outlined above, you can easily add your unique configuration settings to any Laravel 5 application and ensure that they are accessible throughout your project. Remember to always use descriptive and consistent naming conventions for your custom configuration options to promote clarity and ease of use for future developers working on the same project.