Search code examples
phplaravelenv

Laravel 5 - Why second parameter of env()


Almost every php files inside config folder has this function here -> env(). This function take 2 parameters like so :

'driver' => env('MAIL_DRIVER', 'smtp')

I know that the first parameter is to get the right line, but what's the meaning of the second parameter : smtp? I already provided the mail driver inside my .env file but I can't get it why is there 'smtp' inside env()

I looked around and nothing is talking about this. Thanks!


Solution

  • The second value is the default used if Laravel can't find an environment variable with the given key. So if you do have a MAIL_DRIVER environment variable set, that one will be used. If you don't, Laravel will use 'smtp' instead.

    The same system is used for several other things Laravel does as well, for instance trans() and Config::get().