mini-aspire/app/Http/Controllers/API/V1/AuthController.php
/**
     * Create a new user instance after a valid registration.
     */
Create a new user instance after a valid registration.
Create a new user instance after a valid registration .
protected function signup(UserSignupAPIRequest $request)
    {
        try {
            $input = $request->validated();
            $user = User::where('email', $input['email'])->first();
            if ($user) {
                return $this->error("Email is already signuped!", 409); 
            }
            $user = User::forceCreate([
                'name' => $request['name'],
                'email' => $request['email'],           
                'password' => Hash::make($request['password']),
            ]);
            $tokenResult = $user->createToken('Personal Access Token');
            return $this->success("Register successfully.", [
                'access_token' => $tokenResult->accessToken,
                'token_type' => 'Bearer',
                'expires_at' => $tokenResult->token->expires_at,
            ]);
        } catch (\Exception $e) {
            throw $e;
            return $this->error("Something when wrong!", 500);
        }
    }
protected function signup ( UserSignupAPIRequest $ request ) { try { $ input = $ request -> validated ( ) ; $ user = User :: where ( 'email' , $ input [ 'email' ] ) -> first ( ) ; if ( $ user ) { return $ this -> error ( " Email is already signuped! " , 409 ) ; } $ user = User :: forceCreate ( [ 'name' => $ request [ 'name' ] , 'email' => $ request [ 'email' ] , 'password' => Hash :: make ( $ request [ 'password' ] ) , ] ) ; $ tokenResult = $ user -> createToken ( 'Personal Access Token' ) ; return $ this -> success ( " Register successfully. " , [ 'access_token' => $ tokenResult -> accessToken , 'token_type' => 'Bearer' , 'expires_at' => $ tokenResult -> token -> expires_at , ] ) ; } catch ( \ Exception $ e ) { throw $ e ; return $ this -> error ( " Something when wrong! " , 500 ) ; } }
Create a new user instance after a valid registration.
Create a new user instance after a valid registration .
// Check user exist // 409 Conflict // Create new user