Working with custom config settings

.env file

In Laravel you can use the .env file to store also your own custom settings.

You find the .env file in the root folder of your project.


can be retrieved with the env function

echo env('SOMESETTING', 'fallback value');

see: Documentation: env function (helper)

Own custom config files

Another way of storing custom application settings is by using the config way that Laravel is using too.

Create a new file in the /config folder and name that something like appsettings.php or just settings.php. You can have more than one config files to your own taste.

Sample content of the settings.php file

return [
    'somesetting' => 'somevalue'

Now you can use this settings as follows (Laravel 5.4)

namespace Tmdbserver\Http\Controllers;

use Illuminate\Support\Facades\Config;

class SomeController extends Controller {

    public function ShowMySetting() {
        echo Config::get('settings.somesetting', 'fallback value') . '<br/>';
        echo Config::get('settings.anothersetting', 'fallback value');

results in

fallback value
Last update: Tue, 13 Sep 2022 14:32:15