Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 config/app.php url setting

This issue became apparent for me when using dynamic routes within scheduled emails. The email url's are built with this config setting which apparently is not setup to adjust to the server environment. I am using Forge for production. What is best practice for configuring this attribute? Would I add a variable to env files?

Currently its set as follow:

'url' => 'http://localhost',
like image 828
Kevin Compton Avatar asked Oct 22 '25 15:10

Kevin Compton


2 Answers

If your website will be not installed on other domain, then you can assign it via config file directly:

'url' => 'http://localhost',

If your application will be installed/ran in different enviroments or domain you can set it via .env file:

# .env file
APP_URL=http://localhost
like image 185
manix Avatar answered Oct 25 '25 12:10

manix


you have a number of options

1) set config param on the fly in unit test

config(['app.url' => 'https://my.com']);

2) configure it in phpunit.xml file once and for all

<env name="APP_URL" value="my.com"/>

3) change the unittest env on the fly and recreate application in your unit test

$_ENV['APP_URL'] = 'my.com'; $this->refreshApplication();

4) setup the .env variable in the public function setUp(): void of your unit test file before the parent::setUp();

5) modifying your .env file is one of the options too

APP_URL=my.com
like image 25
Yevgeniy Afanasyev Avatar answered Oct 25 '25 13:10

Yevgeniy Afanasyev