app/Http/ApiControllers/UserController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $validator = Validator::make($request->all(), [
              'name'        =>  'required',
              'email'       =>  'required',
              'image'       =>  'required',
              'uid'         =>  'required',
          ]);
         if ($validator->fails()) {
             $this->setError('400');
             $messages=[];
             foreach ($validator->messages()->toArray() as $key=>$value) {
                  $messages[] = (object)['attribue' => $key, 'message' => $value[0]];
             }
             $this->setValidationError(['validation' => $messages]);
             return $this->response('400');
         }
         $user = $request->all();
         $existing_user = User::where('email', '=',  $user['email'])->first();
         $result;
         if (empty($existing_user)) {
             $user['type'] = 0;
             $user['image'] = $user['image'];
             $result = $this->userInterface->store($user);
             if (isset($result)) {
                $result = new UserResource($result);
                $this->data(array($result));
                return $this->response('201');
             }else{
                return $this->response('500');
             }
         }else{
             $existing_user = new UserResource($existing_user);
             $this->data(array($existing_user));
             return $this->response('201');
         }
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'name' => 'required' , 'email' => 'required' , 'image' => 'required' , 'uid' => 'required' , ] ) ; if ( $ validator -> fails ( ) ) { $ this -> setError ( '400' ) ; $ messages = [ ] ; foreach ( $ validator -> messages ( ) -> toArray ( ) as $ key => $ value ) { $ messages [ ] = ( object ) [ 'attribue' => $ key , 'message' => $ value [ 0 ] ] ; } $ this -> setValidationError ( [ 'validation' => $ messages ] ) ; return $ this -> response ( '400' ) ; } $ user = $ request -> all ( ) ; $ existing_user = User :: where ( 'email' , '=' , $ user [ 'email' ] ) -> first ( ) ; $ result ; if ( empty ( $ existing_user ) ) { $ user [ 'type' ] = 0 ; $ user [ 'image' ] = $ user [ 'image' ] ; $ result = $ this -> userInterface -> store ( $ user ) ; if ( isset ( $ result ) ) { $ result = new UserResource ( $ result ) ; $ this -> data ( array ( $ result ) ) ; return $ this -> response ( '201' ) ; } else { return $ this -> response ( '500' ) ; } } else { $ existing_user = new UserResource ( $ existing_user ) ; $ this -> data ( array ( $ existing_user ) ) ; return $ this -> response ( '201' ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .