Laravel: change base URL?

When I use secure_url() or asset() , it refers to my domain domain without "www", that is, example.com.

How can I change it to link to "www.example.com"?

+10
source share
2 answers

First, change the URL of your application in the config / app.php file (or in the APP_URL value of your .env file):

 'url' => 'http://www.example.com', 

Then make the URL generator use it. Add these lines of code to the app / Providers / AppServiceProvider.php file in the download method:

 \URL::forceRootUrl(\Config::get('app.url')); // And this if you wanna handle https URL scheme // It not usefull for http://www.example.com, it just to make it more independant from the constant value if (\Str::contains(\Config::get('app.url'), 'https://')) { \URL::forceScheme('https'); //use \URL:forceSchema('https') if you use laravel < 5.4 } 

These are all people.

+29
source

Laravel uses the current domain when creating secure_url and url (). However, you can configure your defult url in app.php in the config folder.

 /* |-------------------------------------------------------------------------- | Application URL |-------------------------------------------------------------------------- | | This URL is used by the console to properly generate URLs when using | the Artisan command line tool. You should set this to the root of | your application so that it is used when running Artisan tasks. | */ 'url' => 'http://localhost', 
0
source

Source: https://habr.com/ru/post/1242666/


All Articles