SHARE
TWEET

Untitled

a guest Oct 22nd, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function registerUser(Request $request)
  2. {
  3.     $rules = [
  4.         'username' => 'required',
  5.         'email' => 'required|email',
  6.         'password' => 'required|min:5'
  7.     ];
  8.  
  9.     $validator = Validator::make($request->all(), $rules);
  10.  
  11.     if ($validator->fails()) {    
  12.         return response()->json(['errors' => $validator->messages()]);
  13.     }
  14.  
  15.     $user = User::create(request(['username', 'email', 'password']));
  16.  
  17.     return response()->json('success');
  18. }
  19.    
  20. constructor(props){
  21.         super(props);
  22.         this.state={
  23.             userName:'',
  24.             userEmail:'',
  25.             userPassword:'',
  26.             errors:[]              
  27.         }
  28.     }
  29.  
  30.     axios({
  31.         method: 'post',
  32.         url: API_URL+'signup',
  33.         data: {
  34.             username: userName,
  35.             email: userEmail,
  36.             password: userPassword
  37.         }
  38.     })
  39.     .then(function (response) {
  40.         var count = Object.keys(response.data.errors).length;
  41.         if (count > 0) {
  42.             console.log(response.data.errors);
  43.             var newState = new Array();
  44.             newState.push(response.data.errors);
  45.             this.setState({
  46.                 errors: newState
  47.             })
  48.         }
  49.     })
  50.     .catch(function (error) {
  51.         console.log(error);
  52.     });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top