Welcome Guest, Not a member yet? Register   Sign In
Too Many Redirect error if the redirect call is on the same controller
#1

I just noticed that when I call a redirect where the function is inside the same controller, it causes ERR_TOO_MANY_REDIRECTS error. However, when I call a redirect from another controller, it's working as expected.

Code:
public function _remap($method)
    {
        //code to redirect to login if not logged in
        
        if (auth()->loggedIn()) {
            $user = auth()->user();
            if($user->inGroup('admin','superadmin')){
                return redirect()->to('admin/users'); //this causes ERR_TOO_MANY_REDIRECTS
            } else {
                if($user->toRawArray()['is_paid'] == 0){
                    return redirect()->to('payment'); //this is okay
                } else {
                    return $this->{$method}($user->toRawArray());
                }
            }
        } else {
            return redirect()->to(config('Auth')->loginRedirect());
        }
    }
Reply
#2

Yes, if you redirect to the same URL, you will go into infinite loop.
Reply
#3

(This post was last modified: 03-26-2024, 11:39 AM by elimariaaaa.)

So what should I do to stop the loop?

Code:
admin/users
is just:

Code:
public function usersView(){
        $users = auth()->getProvider();
        $user = auth()->user()->toRawArray();
        $data = array(
            'title' => 'Users',
            'users' => $users->where(['id !=' => $user['id']])->findAll() //$userModel->where(['id !=' => $user['id']])->findAll()
        );
        return view('admin/users', $data);
    }

I'm just expecting it to go to URL: admin/users and then show the view.
Reply
#4

(This post was last modified: 03-26-2024, 03:02 PM by kenjis.)

Sorry, I don't understand why do you need infinite loop redirects.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB