Create custom config in Lumen

mAm
mAm
Jan 1, 2019 · 1 min read
Image for post
Image for post

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')

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store