简体   繁体   中英

Laravel: URL::to('/') port number for localhost not included in db seed files

I am running a local server on port 4567. I am trying to make it so that when my database seeds I save a reference to the home page on my site in my db. However I noticed when I run URL::to('\/') in my seeds it only includes "localhost" without the port, but if I include it in my view code it comes out as "localhost:4567". Why is this? How can I fix it, if possibly, without writing if statement conditionals about what production environment I am in? Thank you.

http://localhost

Either set APP_URL in env file

APP_URL=http://localhost:4567

Or set url in config/app.php

'url' => env('APP_URL', 'http://localhost:4567'),

Many internal functions and third-party libraries use the APP_URL .env var directly or via config('app.url')<\/code> . The better way is to use the URL generator classes that Laravel provides, eg. the Url<\/code> facade<\/a> .

In the web context most of Laravel's URL generation is based on the server\/request URL. For example, the url()<\/code> helper calls methods in

That's right, configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM