all(), [ 'email' => 'required', 'password' => 'required', ])->validate(); $credentials = array('email' => $request->email, 'password' => $request->password); $user = User::where('email', $credentials['email'])->first(); if(!@$user){ $user = User::where('username', $credentials['email'])->first(); if ($user && Hash::check($credentials['password'], $user->password)) { // dd($user->group); Auth::attempt(['username' => $request->email, 'password' => $request->password]); $session = [ 'username' => $user->username, 'name' => $user->name, 'email' => $user->email, 'currYear' => date('Y'), 'group_id' => @$user->ms_group_id, 'instansi_id' => @$user->ms_instansi_id, 'group_alias' => @$user->group->alias, 'group_name' => @$user->group->name, ]; session($session); return redirect('dashboard')->with([ 'message' => trans('Selamat datang kembali'), 'type' => "success" ]); }else{ return redirect('/login') ->withInput() ->with([ 'message' => trans('Akun anda tidak ditemukan'), 'type' => "error" ]); } }else{ if ($user && Hash::check($credentials['password'], $user->password)) { Auth::attempt(['email' => $request->email, 'password' => $request->password]); $session = [ 'username' => $user->username, 'name' => $user->name, 'email' => $user->email, 'currYear' => date('Y'), 'group_id' => @$user->ms_group_id, 'instansi_id' => @$user->ms_instansi_id, 'group_alias' => @$user->group->alias, 'group_name' => @$user->group->name, ]; session($session); return redirect('dashboard')->with([ 'message' => trans('Selamat datang kembali'), 'type' => "success" ]); }else{ return redirect('/login') ->withInput() ->with([ 'message' => trans('Akun anda tidak ditemukan'), 'type' => "error" ]); } } } public function logout() { Auth::logout(); return redirect('/login') ->withInput() ->with([ 'message' => trans('Berhasil Keluar'), 'type' => "success" ]); } }