-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
route() helper function does not work well in artisan commands #14139
Comments
Try adding a trailing slash to the URL and/or running |
i tried it before, still the same result |
This is definitely due to an out of date config cache otherwise the cli would have just generated localhost. |
APP URL only work on domain level, right? |
It should be defining the base URI? |
We definitely don't recommend you run apps on sub-folders though. |
Is this a bug? |
Yeh, I'd say so. |
With support @GrahamCampbell I would suggest, leave a slash at trail,laravel will auto handle your route. |
Changing Would that be an acceptable solution for you @GrahamCampbell ? I've run the unit tests and nothing seems to break but I didn't have time yet to check if this part is covered on the tests yet. |
Ok, after further testing the above is not the solution when not using the console. We'll have to find a different fix (and ideally add some test to cover this code). |
The problem seems to come all the way from |
I can't recreate this issue: http://d.pr/i/1bqOj |
I don't think you understood well what the issue is. When the config value of Now, in order to recreate it you'll have to add some path to your base url. |
config('app.url'); I had this issue with the Queues The url helper returns http://localhost |
@engAhmad , if you don't have http[s]?:// prefix to your environment url laravel will not detect it and overwrite it with http://localhost. |
Until the situation is improved, as a workaround you could add this line early: url()->forceRootUrl(config('app.url')); |
Basically the autodetection doesn't work in CLI, and we do have to pass the base URL to the UrlGenerator. I'm posting a few suggestions in #15608. |
I think the reason because some functions use the root as it is calculated by symphony and not based on the env setting. I think the reason is this line: https://github.com/laravel/framework/blob/5.3/src/Illuminate/Http/Request.php#L87 |
Hence the 2 possible fixes I posted in #15608, which make use of We are in CLI so it's normal the request doesn't have an URL. Modifying the request doesn't sound right, while using |
You might be right but I ran into this issue in more cases, not in CLI but in the web (actually on local development on homestead). I just think that if we have an APP_URL environment variable, we should use it - no? |
I can't say for homestead… Let's reference issue #17385 you have just created :) |
Thanks. But what do you think about the general idea of: we already have an APP_URL environment variable, why isn't the url helper use it? |
I'd say because it is not configured by default, so using it would require an extra step in new installs, while the autodetection works in most cases. Also, the autodetection is convenient when the app can be accessed through several domains ;) Don't have to dynamically configure the path. |
Yes you are correct. But in that case I think that A) Why is the APP_URL there and why the laravel config uses it? and B) The auto detection should work flawlessly... at least for web requests... |
@amosmos The |
I had the exact same issue running a Artisan command that should generate my So, in my command
And URLs generation methods used in my Artisan command was based on the Links: pull #15608, stack |
I've looked into Symfony to see how they've solved the problem, when route URL is build from CLI and website is located at sub-path and found this:
It works like this:
Based on that info and @j3j5 comment (see #14139 (comment)) I'm suggesting to change
Code before: $app->instance('request', Request::create(
$app->make('config')->get('app.url', 'http://localhost'), 'GET', [], [], [], $_SERVER
)); Code after: $uri = $app->make('config')->get('app.url', 'http://localhost');
$components = parse_url($uri);
$server = $_SERVER;
if (isset($components['path'])) {
$server['SCRIPT_FILENAME'] = $components['path'];
$server['SCRIPT_NAME'] = $components['path'];
}
$app->instance('request', Request::create($uri, 'GET', [], [], [], $server)); I can send a PR if you'd like as a bugfix. |
In Laravel 5.2.39, my app has
.env
config/app.php
app/Http/routes.php
Artisan command (twilio:setup)
This is what i got from test route
and from php artisan twilio:setup
The text was updated successfully, but these errors were encountered: