Created
February 4, 2020 07:27
-
-
Save godilite/dd0a8390cec4a645f4d58fe7bc7a99d3 to your computer and use it in GitHub Desktop.
Registration Method
This file contains 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
/** | |
* Register api. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function register(Request $request) | |
{ | |
$validator = Validator::make($request->all(), [ | |
'fname' => 'required', | |
'lname' => 'required', | |
'phone' => 'required|unique:users|regex:/(0)[0-9]{10}/', | |
'email' => 'required|email|unique:users', | |
'password' => 'required', | |
]); | |
if ($validator->fails()) { | |
return response()->json([ | |
'success' => false, | |
'message' => $validator->errors(), | |
], 401); | |
} | |
$input = $request->all(); | |
$input['password'] = bcrypt($input['password']); | |
$user = User::create($input); | |
$success['token'] = $user->createToken('appToken')->accessToken; | |
return response()->json([ | |
'success' => true, | |
'token' => $success, | |
'user' => $user | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment