Home > Software design >  Laravel generate routes based on defined url in env file
Laravel generate routes based on defined url in env file

Time:05-27

I use the following method to generate route URLs:

route('example')  

It seems this method generated URLs based on the current URL ($_SERVER['HTTP_HOST']) with binding to the defined routes in api.php file.
How can I use APP_URL defined in env file to generate the URLs instead of the current URL?

CodePudding user response:

If you need to you can force the domain :

URL::forceRootUrl(config('app.url'));

but that's not a good idea, you should always use the domain that the user used to access your app, you will have issues when changing the domain like that, like sessions issues

CodePudding user response:

I think u search for asset() or url()

$url = asset('img/photo.jpg'); // return: http://example.com/assets/img/photo.jpg

here the help https://laravel.com/docs/8.x/helpers#urls

  • Related