Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahoi's avatar
Level 5

Force Route::group(['domain'=>'external.com']) to return https-prefixed routes

Hello everybody,

I created a new routes definition called external.php.

This is how it looks like:

Route::group([
    'domain' => 'example.org'
], function () {
    Route::post('oauth/token')->name('external.oauth.token');

This works fine, so php artisan route:list contains:

| example.org | POST     | oauth/token                | external.oauth.token            | Closure                                                 |                       |

If I do route('external.oauth.token') I am getting this result:

"http://example.org/oauth/token"

So my question is: How can I force the route to be secure/with https-prefix?

0 likes
6 replies
ahoi's avatar
Level 5

This works fine, thanks :-)

One thing seems quite strange: If I use route in my controller, it automatically adds port 8000 to my request.

I guess this is the case, because I am running the php artisan serve which delivers at 8000. Is it possible to remove the port from Route::group?

Nakov's avatar

well php artisan serve runs local server which must include the port. Why don't you use valet if you are on Mac or Homestead on other platforms?

ahoi's avatar
Level 5

My point is:

The route points to an external service. I wanted to create route names for external API endpoints. And the API-Server does not listen on https://...:8000 .

Nakov's avatar

@ahoi I don't get it why do you want to generate routes for external API :)

you should use the services.php file for this, and read an url from your .env file for example:

in .env

API_URL=https://example.org/

in services.php

'api' => [
   'domain' => env('API_URL'),
],

then use it config('services.api.domain').. why do you want to generate routes in your project for a code that you do not own?

1 like

Please or to participate in this conversation.