0

I want to override env data

I overridethe mail service like this

config(['mail.host' => $emails_data->host]);
        config(['mail.username' => $emails_data->username]);
        config(['mail.password' => $emails_data->password]);
        (new MailServiceProvider(app()))->register();

but if I do it for the app it don't work ?

config(['app.debug' => true]);
        (new AppServiceProvider (app()))->register();

How can I override the env data while the app is running ?


I'm trying to add it in Middleware

class DebugBar
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        app('debugbar')->disable();

        if ( Session::get('shop') == 'name' ) {
            // register new config value
            config(['app.debug' => true]);
            (new AppServiceProvider (app()))->register();

             //enable debuger
            app('debugbar')->enable();

        }

        return $next($request);
    }
}
5
  • the .env file should not stay on the server. On the server you should use config files
    – Giacomo M
    Commented Mar 10, 2018 at 0:53
  • you can do that, but the real question is, where are you trying to do it?
    – Ohgodwhy
    Commented Mar 10, 2018 at 1:39
  • @GiacomoMasseroniChiaro even if I used .htaccess to prevent uesers to access it ? ?
    – ahmad
    Commented Mar 10, 2018 at 2:12
  • @Ohgodwhy I'm trying to add it in Middleware I added example above
    – ahmad
    Commented Mar 10, 2018 at 2:13
  • @ahmad to override .env file you have to use laravel config files, not .htaccess file
    – Giacomo M
    Commented Mar 12, 2018 at 9:45

2 Answers 2

0

Environment variables cannot modified by env() or config() helpers.

You need to use putenv() PHP function to overwrite environment variables, e.g. putenv("APP_DEBUG=false");

http://php.net/manual/en/function.putenv.php

1
  • Yes, replace config(['app.debug' => true]); to putenv("APP_DEBUG=false"); Commented Mar 13, 2018 at 23:38
-1

add next on file "app\Providers\AppServiceProvider.php"

    if( env('APP_DEBUG') ) {
    \Debugbar::enable();
}else{
    \Debugbar::disable();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.