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

Bakamashine's avatar

Circular redirection in Laravel

When an entry is opened by id, a round-robin redirection occurs. I can't figure out what the problem is.

Route::middleware("admin")->group(function() {


        Route::get("/admin", [AdminController::class, 'up'])->name("admin");  

        Route::name("type_monsters")->controller(Type_MonsterController::class)->group(function () {
            Route::get("/type_monsters", "up");
            Route::post("/type_monsters/add", "store")->name(".store");
            Route::get("/type_monsters/{bb}/show", "show")->name(".show"); 
        });        
    });

Here is the middleware that is used:

public function handle(Request $request, Closure $next): Response
{
    if (!Auth::check()) {
        return redirect()->route("auth.login"); 
    }
    
    $role = Auth::user()->role_id;
    
    if ($role !== 1) {
        abort(403, 'Forbidden'); 
    }
    
    return $next($request);
}

Is that the case, or is there something else that can cause this behavior? Laravel 11

0 likes
7 replies
Sinnbeck's avatar

Please show Type_MonsterController. I assume its the show route you are referring to causing the issue?

Sinnbeck's avatar

Also if you have ANY other routes before these, there is a chance you are hitting one of them.

Bakamashine's avatar

@Sinnbeck

Type_MonsterController:

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Bakamashine This just redirects to itself?

public function show(Type_Monster $id) {
        return redirect()->route("type_monsters.show", ['id' => $id]);
    }

I assume you want to return a view instead of a redirect

1 like
tykus's avatar

@bakamashine you are also using Route-Model binding incorrectly; the parameter on the Controller action ($id) should match the wildcard parameter in the URL {bb}, otherwise you will get an "empty" Type_Monster instance - that does not exist in the database:

Route::get("/type_monsters/{monster}/show", "show")->name(".show"); 
public function show(Type_Monster $monster) {
    return view('monsters,show', ['monster' => $monster]);
}
1 like
tykus's avatar

When an entry is opened by id

What does this mean; which route are you visiting?

Please or to participate in this conversation.