zoey
zoey

Reputation: 47

Out of a sudden my /admin route inside the Auth Middleware in Laravel 8 returns a 404 not found

I recently started to code my own Admin panel in Laravel. Every route was working fine, but all of a sudden the /admin route inside the Auth middleware group stopped working properly.

This are my routes inside web.php

My php artisan route:list

And the EntryController@index looks like this:

public function index()
{
    //
    $entries = Entry::all();
    return view('admin.index', ['entries' => $entries]);
}

I'm having this problem for about 2 now, so maybe one of you know the solution.

Upvotes: 1

Views: 287

Answers (1)

acvi
acvi

Reputation: 111

I think you're having this issue because of how Laravel prioritises its routes.

And I think the culprit might be this route:

Route::get('/{link}', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

When you use {link} you are basically saying: "expect anything in this segment of the URI". Since the /{link} route is placed before the /admin route, and their URIs both contain only one segment, Laravel will try to resolve /{link} first.

Solution: just move the /{link} route below the /admin route. Might be best to just place it at the bottom of the list :D

Upvotes: 0

Related Questions