Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GodziLaravel's avatar

what's the best place to store the constants variables in lumen

Hello , I work on a rest API service and some parameter can take default values like : offset, limit, order by...

I would like to know where to store those values (I think of .env, is it the best way ? )

thnaks

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

.env is intended for per-environment configuration and sensitive credentials.

You can maintain a config with this type of data. There is no default config for Lumen like there is for Laravel, so you need to add the required config directory, and tell Lumen to use it:

$ mkdir config
$ touch config/app.php

In the app.php file, you can return an array with the config:

// config/app.php
<?php
return [
    'order_by' => 'whatever'
    // and so on
];

Then tell Lumen to load the config from app.php inside bootstrap/app.php, by adding (after $app has been initialised):

$app->configure('app');

Finally, you can use the config() helper method to get the configuration:


config('app.order_by') // whatever

Please or to participate in this conversation.