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

ChristopherSFSD's avatar

Laravel 8 404 Everywhere and Routes Missing

I've been upgrading a project from Laravel 5.3. I managed to do just fine all the way through Laravel 7. But after upgrading to Laravel 8, everything is returning 404. When I php artisan route:list, all I see is a broadcasting/auth route - all of my routes are missing.

Any ideas could be helpful. Thanks!

0 likes
16 replies
tykus's avatar

Share your routes file(s) and your RouteServiceProvider class.

ChristopherSFSD's avatar

Okay. I have removed some of it for simplicity and yes, I've tested removing all but the home route and commenting out all the stuff I added to the boot method to no avail.

I've also tried changing the namespace of RouteServiceProvider to match the default but that resulted in the ServiceProvider not being found. I'd rather not change its namespace from what I use anyway because this is a gigantic App with a lot of classes in the 'MyApp' namespace. It's not really 'MyApp' but I've altered the name for this example.

All of this worked perfectly in Laravel 5.3 through Laravel 7

#RouteServiceProvider:

<?php

namespace MyApp\Providers;

use Carbon;
use Illuminate\Http\Request;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
use MyApp\Services\Help\HelpProvider;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use MyApp\Services\Maintenance\Quotes\Requests\QuoteRequestProvider;
use MyApp\Services\Maintenance\Quotes\Responses\QuoteResponseProvider;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * The path to the "home" route for your application.
     *
     * This is used by Laravel authentication to redirect users after login.
     *
     * @var string
     */
    public const HOME = '/home';

    /**
     * The controller namespace for the application.
     *
     * When present, controller route declarations will automatically be prefixed with this namespace.
     *
     * @var string|null
     */
    protected $namespace = 'MyApp\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        $this->configureRateLimiting();

        $id_pattern = '^[0-9]+$';
        $guid_pattern = '^[A-F|0-9]{12}$';

        Route::pattern('quote_response', $guid_pattern);
        Route::pattern('quote_request', $guid_pattern);
        Route::pattern('reference_document', $guid_pattern);

        Route::pattern('help_doc', $id_pattern);

        Route::pattern('schedule_type', 'initial|recurring');
        Route::pattern('component_set', 'detached|attached');

        Route::model('help_doc', \HelpDocument::class, function()
        {
            throw new ModelNotFoundException(trans('resource.not_found', ['r' => trans('help.document')]));
        });

        Route::model('reference_document', \ReferenceDocument::class, function()
        {
            throw new ModelNotFoundException(trans('resource.not_found', ['r' => trans('reference.document')]));
        });

        // CUSTOM BINDINGS:
        Route::bind('help_doc_slug', function($value)
        {
            if ($help_doc = app(HelpProvider::class)->locateDocument($value))
            {
                return $help_doc;
            }

            throw new ModelNotFoundException(trans('resource.not_found', ['r' => trans('help.document')]));
        });

        Route::bind('quote_request', function($value)
        {
            if ($quote_request = app(QuoteRequestProvider::class)->findByID($value))
            {
                return $quote_request;
            }

            throw new ModelNotFoundException(trans('resource.not_found', ['r' => trans('quote.request')]));
        });

        Route::bind('quote_response', function($value)
        {
            if ($quote_response = app(QuoteResponseProvider::class)->findByID($value))
            {
                app(QuoteRequestProvider::class)->populate($quote_response->QuoteRequest);

                return $quote_response;
            }

            throw new ModelNotFoundException(trans('resource.not_found', ['r' => trans('quote.request')]));
        });

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

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

    public function register()
    {
        //
    }

    /**
     * Configure the rate limiters for the application.
     *
     * @return void
     */
    protected function configureRateLimiting()
    {
        RateLimiter::for('api', function (Request $request) {
            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
        });
    }
}

#Web Routes:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// AUTHENTICATION
Route::get('login', ['as' => 'login', 'uses' => 'AuthController@getLogin', 'middleware' => 'guest']);
Route::get('auth/login', function() { return redirect('login'); });
Route::post('login', ['as' => 'login', 'uses' => 'AuthController@login']);
Route::get('logout', ['as' => 'logout', 'uses' => 'AuthController@logout', 'middleware' => 'auth']);

// HOME PAGE:
Route::get('home', ['as' => 'home', 'uses' => 'HomeController@getIndex']);

// SENDS AUTHENTICATED USERS TO THE DASHBOARD, NON-AUTHENTICATED USERS TO THE HOME PAGE:
Route::get('/', function() { return (Auth::check()) ? Redirect::route('dashboard') : Redirect::route('home'); });

// NAVIGATION:
Route::get('top-bar', ['as' => 'top-bar.get', 'uses' => 'NavigationController@getTopBar']);

// CONTACT US:
Route::get('contact', ['as' => 'contact.new', 'uses' => 'ContactController@getIndex']);
Route::post('contact', ['as' => 'contact.create', 'uses' => 'ContactController@postCreate']);

// EMAIL OPT-OUT / BLACKLISTING:
Route::get('email/optout', ['as' => 'email.optout.new', 'uses' => 'EmailController@getIndex']);
Route::post('email/optout', ['as' => 'email.optout.create', 'uses' => 'EmailController@create']);

Amaury's avatar

@[email protected] Hi, did you try to clear the cache of your application, your configuration and your views? It could help… or not!

ChristopherSFSD's avatar

@amaury Yes. I believe I cleared everything. route:clear, cache:clear, optimize:clear. Route list still shows one broadcasting route, no other routes are listed.

ChristopherSFSD's avatar

@amaury yes. Optimize:clear clears all that stuff but I did view:clear anyway as I’m grasping for straws.

ChristopherSFSD's avatar

Some tests are broken. I figured I was going to have to address tests but figured I'd wait until I got through upgrading from L5.3 to L10 or L11. A lot of my tests were in behat and integration. However it does pass over 500 unit tests (12K+ assertions) with loads of warnings about prophesize().

ChristopherSFSD's avatar

Okay but I don't use named routes and it worked fine in Laravel 7. If I drop my RouteService Provider down to this ...

<?php

namespace MyApp\Providers;

use Carbon;
use Illuminate\Http\Request;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    public const HOME = '/home';

    protected $namespace = 'MyApp\Http\Controllers';

    public function boot()
    {
        $this->configureRateLimiting();

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

    public function register()
    {
        //
    }

    protected function configureRateLimiting()
    {
        RateLimiter::for('api', function (Request $request) {
            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
        });
    }
}

... and my routes/web.php down to this ...

<?php

Route::get('home', ['as' => 'home', 'uses' => 'HomeController@getIndex']);

Then php artisan optimize:clear, route:clear, cache:clear, view:clear, then php artisan route:list I still don't see my home route. All I see is ...

+--------+---------------+-------------------+------+----------------------------------------------------------+------------+
| Domain | Method        | URI               | Name | Action                                                   | Middleware |
+--------+---------------+-------------------+------+----------------------------------------------------------+------------+
|        | GET|POST|HEAD | broadcasting/auth |      | Illuminate\Broadcasting\BroadcastController@authenticate | web        |
+--------+---------------+-------------------+------+----------------------------------------------------------+------------+

Amaury's avatar

@[email protected] did you try to remove the $namespace property from the RouteServiceProvider and to import the controllers within the routes?

Try to use named routes too.

ChristopherSFSD's avatar

@amitsolanki24_

use MyApp\Http\Controllers\HomeController;

Route::get('home', [HomeController::class, 'getIndex'])->name('home');

Cleared routes, route list still doesn't show the home route.

ChristopherSFSD's avatar

@amaury Commented out the namespace property and added to web.php...

use MyApp\Http\Controllers;

Cleared routes. No change.

ChristopherSFSD's avatar

I did the following as suggested by @amitsolanki24_

use MyApp\Http\Controllers\HomeController;

Route::get('home', [HomeController::class, 'getIndex'])->name('home');

But again, no change.

I may just need to create a fresh Laravel install and move things over but I’m not looking forward to that prospect as it’s a really large app.

Please or to participate in this conversation.