Laravel: Change base URL?

后端 未结 1 2062
刺人心
刺人心 2020-12-06 01:34

When I use secure_url() or asset(), it links to my site\'s domain without \"www\", i.e. \"example.com\".

How can

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 02:01

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

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

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

    \URL::forceRootUrl(\Config::get('app.url'));    
    // And this if you wanna handle https URL scheme
    // It's not usefull for http://www.example.com, it's 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
    }
    

    That's all folks.

    0 讨论(0)
提交回复
热议问题