Looks like the URLGenerator is not getting the app.url from the app container.
> php artisan tinker
Psy Shell v0.10.3 (PHP 7.4.0 — cli) by Justin Hileman
>>> config('app.url')
=> "http://laravel.com"
>>> config()->set('app.url', 'http://spatie.be');
=> null
>>> config('app.url')
=> "http://spatie.be"
>>> url('/random')
=> "http://laravel.com/random"
>>>
Can confirm.
could you try config clear before using url(), maybe url generator is generating route based on cached root
illuminate\Routing\UrlGenerator::class : line 61
/**
* A cached copy of the URL root for the current request.
*
* @var string|null
*/
protected $cachedRoot;
We removed the behavior of setting the app url through the config in https://github.com/laravel/framework/pull/32345 because we want to let the router take care of setting the url. The previous behavior was actually sort of work around for an old issue. This wasn't documented either.
We actually have a dedicated way for the router to set the base url for routing which is URL::forceRootUrl('http://api.app.test');. Can you try that?
@driesvints , yeah, that works fine. So maybe we could raise an exception when someone tries to set app.url at runtime? Because looks like, somehow, this works sometimes. I actually found that working on a Spatie package, one the tests were failing because of this, but the one on master is probably passing fine.
Thank you!
Hey guys!
Just saw this by pure luck and got a little worried because we're doing this in a Laravel 6 app that we're going to upgrade to Laravel 7 in the coming weeks.
But I think we're already covered. Is there any difference between this two?
A. URL::forceRootUrl('http://api.app.test')
B. app('url')->forceRootUrl('http://api.app.test')
We also set the app.url a line after the app('url')->forceRootUrl(...
No, they're the same.
Most helpful comment
@driesvints , yeah, that works fine. So maybe we could raise an exception when someone tries to set app.url at runtime? Because looks like, somehow, this works sometimes. I actually found that working on a Spatie package, one the tests were failing because of this, but the one on master is probably passing fine.
Thank you!