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

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.

public function _remap($method)
        //code to redirect to login if not logged in
        if (auth()->loggedIn()) {
            $user = auth()->user();
                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());

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

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

So what should I do to stop the loop?

is just:

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.

(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.

Theme © iAndrew 2016 - Forum software by © MyBB