Create custom config in Lumen

mAm
1 min readJan 1, 2019

--

Follow these 3 steps to do this.

  1. Open your .env file and add your configuration, for an example PAGINATION_LIMIT=100 (we can access this value via env() helper function, but it is always recommended to access your configuration via config() helper function)
  2. Create config directory in your project’s root directory
  3. Create your configuration file inside config directory, for an example product.php
  4. Your configuration files always lives in ROOT_DIR/config/
  5. Add your configuration in product.php like the following
<?php
/**
*
@category Product-service
*
@package Product
*
@author mAm <mamreezaa@gmail.com>
*/

return [

/*
|--------------------------------------------------------------------------
| Pagination
|--------------------------------------------------------------------------
|
| This value gives, the maximum number of records a request can return
|
*/
'pagination' => env('PAGINATION_LIMIT', 100),

];

6. If you look at this file, it only return an array of configurations, you can add more configuration like you add more elements to an array.

7. Now we need to inform Lumen, that we have a new configuration file that it has to load when the application stat to run. to do that open your bootstrap/app.php file and add $app->configure(product) after variable $app initiated.

DONE

We can get this configuration using config() helper function.

Ex: config('product.pagination')

--

--