Laravel is "generic" in development versus production

I am working with Laravel 5.2 application. In my development and staging environment, I would like to use the "Universal To" email option described in the docs . A universal development environment ensures that all emails are sent to this address and not to real clients / clients / whatever.

I cannot figure out how to specify this differently in production. There should be no universal in production - emails should go to real addresses.

The standard approach of using different values env()

doesn't work. For example:

config / mail.php

'to' => [
    'address'   => env('UNIVERSAL_TO', false)
],

      

.env development :

UNIVERSAL_TO=my-testing-address@somewhere.com

      

This works great - all emails are sent to the specified UNIVERSAL_TO

one as expected. But if I change this to whatever I want in production, like:

production.env

UNIVERSAL_TO=

      

(or =''

or =false

, or just completely eliminating this), sending any mail with an error (in storage/laravel.log

):

local.ERROR: "Swift_RfcComplianceException" with the message "The mailbox address specified by [] does not comply with RFC 2822, 3.6.2. in path / to / vendor / swiftmailer / swiftmailer / lib / classes / Swift / Mime / Headers / MailboxHeader.php: 348

config/mail.php

just returns an array, so I suppose I could instead set it as a variable and then depending on the environment add "to" to it, like this:

$return = [ ... normal mail config array ... ];

if (!\App::environment('production')) {
    $return['to'] => [
        'address' => 'my-testing-address@somewhere.com'
    ];
}

return $return;

      

But that seems a little ... brave. Is there a better way?

+3


source to share


2 answers


I think this should work - it leaves config('mail.to')

as null

if not installed UNIVERSAL_TO

.



'to' => env('UNIVERSAL_TO', false) ? [
    'address' => env('UNIVERSAL_TO'),
] : null,

      

+1


source


Yes, I am still doing what you call hacking and I haven't found a better way yet.



$default = [
    ....
]

if (env('APP_ENV', 'local') === 'staging'){
    $default['to'] = [
        'address' => 'webmaster@xxx.com',
    ]
}

return $default;

      

0


source







All Articles