app/Http/ApiControllers/UserController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $validator = Validator::make($request->all(), [
              'email'     =>  'email',
              'date_of_birth'=> 'date',
              'image'     =>  'image',
              'admin_id'  =>  'exists:admin,id'
          ]);
         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 = $this->userInterface->find($id);
        if (isset($request->editedby)) {
            $date = new DateTime();
            $date = $date->format('Y-m-d H:i:s');
           if ($request->type == 'student') {
              $code = (string) Uuid::generate();
              $qr  = (object) ['user_id'=>$user->id, 'code'=>$code];
              event(new IntakeConfirmEvent( $user->email, $qr));
              event(new ContentCRUDEvent('Promote', $request->admin_id, 'Student', 'Promoted '. $user->name . ' to student.'));
              $noti = [
                'user_id'=>$user->id,
                'type' => 0,
                'title'=> 'Promoted',
                'descriptions'=> "Congratulations! you have been selected as on of a few talented people. ",
                'date' => $date
              ];
              $this->storeNotification($user, $code, $noti);
           }else{
              event(new ContentCRUDEvent('Demote', $request->admin_id, 'Student', 'Demoted '. $user->name . ' to normal user.'));
              $noti = [
                'user_id'=>$user->id,
                'type' => 0,
                'title'=> 'Demote',
                'descriptions'=> "Sorry to inform you that you have been removed from our student list. ",
                'date' => $date
              ];
              $this->storeNotification($user, null, $noti);
           }
        }
        if (empty($user)) {
            $this->setError('404', $id);
            return $this->response('404');
        }else{
            $user = $request->all();
            try {
              if ($request->editedby) {
                $user['type'] = 0;
              }else{
                $user['type'] = $this->convertUserType($user['type'], 0);
              }
            } catch (\Exception $e) {
            }
            try {
              $user['gender'] = $this->convertGender( $user['gender'], 0);
            } catch (\Exception $e) {
            }
            if ($this->userInterface->update($user,$id)) {
                $this->data(array('updated' =>  1));
                return $this->response('200');
            }else{
                return $this->response('500');
            }
        }
    }
public function update ( Request $ request , $ id ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'email' => 'email' , 'date_of_birth' => 'date' , 'image' => 'image' , 'admin_id' => 'exists:admin,id' ] ) ; 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 = $ this -> userInterface -> find ( $ id ) ; if ( isset ( $ request -> editedby ) ) { $ date = new DateTime ( ) ; $ date = $ date -> format ( 'Y-m-d H:i:s' ) ; if ( $ request -> type == 'student' ) { $ code = ( string ) Uuid :: generate ( ) ; $ qr = ( object ) [ 'user_id' => $ user -> id , 'code' => $ code ] ; event ( new IntakeConfirmEvent ( $ user -> email , $ qr ) ) ; event ( new ContentCRUDEvent ( 'Promote' , $ request -> admin_id , 'Student' , 'Promoted ' . $ user -> name . ' to student.' ) ) ; $ noti = [ 'user_id' => $ user -> id , 'type' => 0 , 'title' => 'Promoted' , 'descriptions' => " Congratulations! you have been selected as on of a few talented people.  " , 'date' => $ date ] ; $ this -> storeNotification ( $ user , $ code , $ noti ) ; } else { event ( new ContentCRUDEvent ( 'Demote' , $ request -> admin_id , 'Student' , 'Demoted ' . $ user -> name . ' to normal user.' ) ) ; $ noti = [ 'user_id' => $ user -> id , 'type' => 0 , 'title' => 'Demote' , 'descriptions' => " Sorry to inform you that you have been removed from our student list.  " , 'date' => $ date ] ; $ this -> storeNotification ( $ user , null , $ noti ) ; } } if ( empty ( $ user ) ) { $ this -> setError ( '404' , $ id ) ; return $ this -> response ( '404' ) ; } else { $ user = $ request -> all ( ) ; try { if ( $ request -> editedby ) { $ user [ 'type' ] = 0 ; } else { $ user [ 'type' ] = $ this -> convertUserType ( $ user [ 'type' ] , 0 ) ; } } catch ( \ Exception $ e ) { } try { $ user [ 'gender' ] = $ this -> convertGender ( $ user [ 'gender' ] , 0 ) ; } catch ( \ Exception $ e ) { } if ( $ this -> userInterface -> update ( $ user , $ id ) ) { $ this -> data ( array ( 'updated' => 1 ) ) ; return $ this -> response ( '200' ) ; } else { return $ this -> response ( '500' ) ; } } }
Update the specified resource in storage.
Update the specified resource in storage .
// dd($request->type); // $request->type = $user->type;