Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function login(Request $request){
- try {
- //code...
- $validator = Validator::make($request->all(), [
- 'username' => 'required|max:255',
- 'password' => 'required|max:255',
- ]);
- if ($validator->fails()) {
- return $this->getResponse(406, $validator->errors()->first());
- }
- $username = $request->username;
- $user = Users::where('username', $username)->orWhereHas('profile', function ($query) use ($username) {
- $query->where('email', $username)->orWhere('phone', $username);
- })->where('status', 1)->first();
- // dd($user);
- if (!$user) {
- # code...
- return $this->getResponse(401, 'Username doesnt match');
- }
- if (!Hash::check($request->password, $user->password) ) {
- # code...
- return $this->getResponse(401, 'Password doesnt match');
- }
- $token = $this->generateToken($user);
- if (!$token) {
- # code...
- return $this->getResponse(500);
- }
- return $this->getResponse(200, false, [
- 'token' => $token
- ]);
- } catch (\Throwable $th) {
- // throw $th;
- return $this->getResponse(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment