コード例 #1
0
ファイル: AuthController.php プロジェクト: rajabishek/begin
 /**
  * Handle a registration request to the application.
  *
  * @param \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function postRegister(Request $request)
 {
     try {
         $this->validate($request, ['email' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|confirmed|min:4']);
         $data = $request->only('name', 'email', 'password');
         $user = $this->users->create($data);
         $token = Auth::generateTokenById($user->id);
         return $this->respondWithSuccess(compact('token'));
     } catch (ValidationException $e) {
         return $this->respondUnprocessableEntity($e->getErrors()->all());
     } catch (Exception $e) {
         return $this->respondInternalError();
     }
 }