Last active
April 22, 2020 13:19
-
-
Save Cerwyn/8faaafe75102cf8c2c42aff939400f68 to your computer and use it in GitHub Desktop.
generalizing-response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers\User; | |
| use App\User; | |
| use Illuminate\Http\Request; | |
| use Illuminate\Support\Facades\Hash; | |
| use Illuminate\Support\Facades\Validator; | |
| use App\Http\Controllers\ApiController; | |
| class UserLoginController extends ApiController | |
| { | |
| public function store(Request $request) | |
| { | |
| $validator = $this->validateEmail(); | |
| if ($validator->fails()){ | |
| return $this->errorResponse($validator->messages(), 422); | |
| } | |
| $user = User::where('email',$request->email)->firstOrFail(); | |
| if(Hash::check($request->password,$user->password)){ | |
| return $this->successResponse($user); | |
| } | |
| return $this->errorResponse('Password Wrong',401); | |
| } | |
| public function validateEmail(){ | |
| return Validator::make(request()->all(), [ | |
| 'email' => 'required|string|email|max:255', | |
| ]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment