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

lancis's avatar
Level 11

Laravel 8 Route Problem

Hi Guys,

With the new Laravel 8, there seems to be a slight problem with the way routes are handled atleast in this case.

If we use this declaration in routes/web.php :

Route::any('{any}', function () { return view('app'); })->where('any', '.*');

all the api routes defined in routes/api.php are inaccessible which is not the case with Laravel 7. Any possible reason for this?

0 likes
4 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

It seems that they were flipped.

Laravel 7 api is first https://github.com/laravel/laravel/blob/7.x/app/Providers/RouteServiceProvider.php

 public function map()
    {
        $this->mapApiRoutes();

        $this->mapWebRoutes();

        //
    }

Laravel 8 web is first https://github.com/laravel/laravel/blob/master/app/Providers/RouteServiceProvider.php

$this->routes(function () {
            Route::middleware('web')
                ->group(base_path('routes/web.php'));

            Route::prefix('api')
                ->middleware('api')
                ->group(base_path('routes/api.php'));
        });

I am sure you can just swap them back

1 like
lancis's avatar
Level 11

Got it. Nice catch. I have review this part once or twice before asking, but the though of switching it do not cross my mind. Thanks a lot.

Sinnbeck's avatar

Yeah this chance seems like a bad idea. I am unsure why it was implemented in that order.

1 like

Please or to participate in this conversation.