swm
swm

Reputation: 539

OR conditional in authentication - LARAVEL

I am doing the conditional authentication for the login so the user will redirect to their pages respectively. My code is:

protected $redirectTo = '/';

    protected function redirectTo()
    {
        if (auth()->user()->department == 'HR' || 'Human Resource' ) {
            return '/hr';

        }
        elseif (auth()->user()->department == 'Accountant' || 'ACC' ) {
            return '/acc';
        }
        else return '/';
    }

However, when I run the code, the page is redirected to the wrong page. How to add OR clause to the parameter?

Upvotes: 1

Views: 69

Answers (2)

VIKAS KATARIYA
VIKAS KATARIYA

Reputation: 6005

Try This Not Use directly ||

((auth()->user()->department == 'HR') || (auth()->user()->department == 'Human Resource'))

((auth()->user()->department == 'Accountant') || (auth()->user()->department == 'ACC'))

Upvotes: 1

Akash Kumar Verma
Akash Kumar Verma

Reputation: 3318

protected function redirectTo()
{
    if ((auth()->user()->department == 'HR') || (auth()->user()->department == 'Human Resource')) {
        return '/hr';

    }
    elseif ((auth()->user()->department == 'Accountant') || (auth()->user()->department == 'ACC')) {
        return '/acc';
    }
    else return '/';
}

Upvotes: 1

Related Questions