I'm trying to make simple admin function to disable/enable users rather than delete them.
So far I have admin function which successfully update table users and change the status to 0(enabled) and 1(disabled).
Now I have problems when user trying to log and checking his status.
This is my function for login in UserController.php
public function loginSubmit() {
$user = User::where('username', Input::get('username'))->first();
if (!$user) {
$validator->messages()->add('username', 'Invalid login or password.');
return Redirect::to('/users/login')->withErrors($validator->errors())->withInput(Input::except(['captcha']));
}
$user = User::where('is_disabled', 0)->first();
if ($user->is_disabled == 1) {
$validator->messages()->add('username', 'User not found.');
return Redirect::to('/users/login')->withErrors($validator->errors())->withInput(Input::except(['captcha']));
}
$user->last_login = \Carbon\Carbon::now();
$user->save();
Session::put('user', ['user_id' => $user->user_id]);
return Redirect::to('/');
}
The problem is that when the condition is true ($user->is_disabled == 1)
it is logged me in with the next user from table e.g. first user which is is_disabled = 0.
How can I make this in proper way?