Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login a user only if his status is active in Laravel 5.7

I am new to Laravel and have been fairly successful in implementing user authentication. Now to move on to the next step I must allow only users whose status in active to login. For that I have added a

status TINYINT

column in my mysql users table.

I found this in the Laravel Documentation:

Specifying Additional Conditions

If you wish, you may also add extra conditions to the authentication query in addition to the user's e-mail and password. For example, we may verify that user is marked as "active":

if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
// The user is active, not suspended, and exists.
}

Can someone please point out where I need to put this chunk. Am thoroughly confused and need some pointers.

Thanks

like image 401
Debajeet Choudhury Avatar asked Dec 14 '18 13:12

Debajeet Choudhury


People also ask

How do I enable authentication in Laravel?

Just run php artisan make:auth and php artisan migrate in a fresh Laravel application. Then, navigate your browser to http://your-app.test/register or any other URL that is assigned to your application. These two commands will take care of scaffolding your entire authentication system!


1 Answers

Have this on your LoginController:

protected function credentials(Request $request)
{        
   return ['username' => $request->{$this->username()}, 'password' => $request->password, 'status' => 1];
}
like image 159
kapitan Avatar answered Oct 21 '22 04:10

kapitan