Laravel framework 5.0 article

Home >> Laravel framework 5.0 >>

  Create custom config file in laravel

This article will explain you, how to create new config file in the Laravel 5 framework to store all my constants in it. Let's take an example, you want to keep some constant like your website name and email address etc... You can keep all constant at one place and call them dynamically, if in the future you want to change something, then you need to change at one place and it will get reflected everywhere, because you are calling them dynamically.

Follow below steps to create the custom config file.

1. Create new file constants.php inside config directory
2. Paste the below code in constants.php file

<?php
// This is just an example, you can keep any name of your constant and value also.
return [
    'APP_SITE_NAME' => 'phpcodehub',
    'APP_SITE_EMAIL' => 'query@phpcodehub'
];

?>


3. Access your constant in controller

<?php

   config('constants.APP_SITE_NAME');
   
?>

Comments

query

what is the need of 'APP_SITE_EMAIL' => 'query@phpcodehub'

  2 years ago      priyanka      
It's just an example of constant.
Re : query.

Priyanka it's just an example of constant, you can keep any name as you want.

  2 years ago      Php Code Hub      

Write your comment now