Laravel Configuration In Hindi

📔 : Laravel 🔗

Laravel Framework के लिए सभी configure files config directory में होती है। इन्ही configure files के through ही हम Email , Database या Other Options (Like : SMS etc . ) को config करते हैं। इस topic में आप सभी available options के बारे में पढ़ेंगे।

1. Configuration Values

config directory में सभी files एक Associated Array (Single या Multidimensional Array) को return करती हैं , जिसमे key => value pair में values define की जाती है।

Accessing Configuration Values

configuration files से values को access करने के लिए config() helper function का use करते है। जिसमे filename के साथ Array key pass करते हैं जिससे value associate है।

config('file_name.key');
For Example : Getting App Name that is defined in config/app.php
config('app.APP_NAME');

इसमें app एक file का name है और APP_NAME Array key है।


और अगर आप Run Time पर किसी value को change / update करना कहते हैं तो config() helper function में ही key => value pair में Array pass कर देते हैं।
For Example :

config(['app.APP_NAME' => 'New Name']);

2. Environment Configuration

किसी भी fresh Laravel Project के root directory में ही , एक .env file होती है , जो कि project के सभी default setting variables को hold करती है। Setting Options like Database , Email etc.. को आप यही से directly set कर सकते हैं। इसके लिए आपको configuration files में change करने की जरूरत नहीं है।

Defining Environments Variable

अगर आपको अपनी कोई custom value define करनी है तो simply एक normal variable की तरह define कर सकते हैं।

File : .env

APP_NAME="My Application"

Retrieving Environments Variable

file की values को आप 2 तरह से retrieve कर सकते हैं।

  1. $_ENV super global variable के through
  2. env() helper function के through

For Example :

$_ENV['APP_NAME'];
  Or
env('APP_NAME');

दोनों में से आप कोई भी तरीका use कर सकते हैं।

3. Debug Mode

debug option config/app.php में होता है , जो यह निर्धारित करता है की किसी भी error के बारे में कितनी information end user को दिखे। यह option APP_DEBUG की value के according result show करता है। जो .env में defined होता है।


By default debug mode Laravel में true होता है , जिसक मतलब होता है कि अगर कही error आती है तो उस error के बारे में full information आपको दिखेगी जिससे आप उसे debug कर सकें।


? आपके production environment में, APP_DEBUG की value हमेशा false होना चाहिए। यदि variable production में true है तो end user आने वाली errors के बारे सब कुछ जान सकता है जो , की किसी भी web application के लिए अच्छा नहीं है।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers