Support the ongoing development of Laravel.io →
Nova Laravel
0
moderator

Hello @azim1728

Do you get redirected to the same page or between multiple pages? That can make a different where you need to check it :)

Small sidenote, you can get the user with $request->user();

0

Hey @tvbeek ,

I get redirected to the same page even if I am on that particular page.

Thanks for your sidenote.

0
moderator

I see 2 possible reasons:

  1. $request->route()->getName() result in another name then any name in the array. You could check it with a dd() in the if statement.
  2. There is another middleware that result in a new redirect, you could check it with a dd() before the next to see if you are there.

Example:

    public function handle(Request $request, Closure $next): Response
    {
        $user = auth()->user();

        if ($user && $user->passwordChangedAt === null && !$this->shouldExcludeRoute($request)) {
            dd('name mismatch', $request->route()->getName(),);
            return redirect()->route('nova.pages.password.email');
        }
        dd('we execute next, that means the problem is not in this middleware.');
        return $next($request);
    }
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Azim Belim azim1728 Joined 14 Mar 2023

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.