Some strange errors in Laravel 11

These are some strange behaviors I’m talking about:

Every time I access a link which is going to access a Route, it always redirects to 127.0.0.1:9002 though my ‘php artisan serve’ is running on port 8000. This happens to all links which are supposed to access a Route.
Unfortunately, it always shows "127.0.0.1 refused to connect’. The address bar shows “(external page)”, of course it is not (external).
When I tried to run ‘php artisan serve --port 9002’ I got the message “Failed to listen on 127.0.0.1:9002 (reason: Address already in use)”.
If I replace the url to direct link such as folder/file.php it goes well. I found that the error occurs only when the link has an action to a Route {{ route(‘route_name’) }}.

Also, my php is running though I have not run ‘php artisan serve’ yet. I don’t think it is possible if I use Laragon or XAMPP.

Are you setting Laravel up through the template?

1 Like

Yes. I chose Laravel setting provided by Project Idx.

Try modify your
bootstrap/app.php

->withMiddleware(function (Middleware $middleware) {
        ...

        // add this line.
        $middleware->trustProxies(at: ['127.0.0.1']);
 })

and

app/Providers/AppServiceProvider.php

public function boot(): void
{
     // add this line.
    \Illuminate\Support\Facades\URL::forceScheme('https');
}
1 Like

This works, big thanks!!