我在电子商务网站上工作
- 1- 项目后端和 API。2-客户端[前端]项目。
1-这是后端项目中的功能..
public function register(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required',
'email' => 'required|email|unique:users',
'password' => 'required',
'mobile' => 'required|unique:users',
'country_id' => 'required'
]);
if ($validator->fails()) {
return response()->json(['error'=>$validator->errors()], 401);
}
$input = $request->all();
$input['password'] = bcrypt($input['password']);
$user = User::create($input);
$success['token'] = $user->createToken('MyApp')-> accessToken;
$success['name'] = $user->name;
return response()->json([
'status' => 'success',
'data' => $success,
], 200);
}
2-来自客户端的此功能。
protected function register(Request $request)
{
$response = \Curl::to('http://localhost/backend/public/api/v1/client-register')->withData(
[
'name'=> $request->name,
'email'=> $request->email,
'password'=> $request->password,
'mobile'=>$request->mobile,
'role_id'=>5,
'country_id'=> $request->country_id
])->post();
$data = json_decode($response, true);
// what i need here
/*check if(response success){
/ go to route('bla bla');
}else{
return back with msg
please help
}**/
}
**请帮助:如果成功,我需要处理响应,如果失败,则返回路由 A,返回消息!