app/Http/ApiControllers/CommentController.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(), [
                        'user_id'       =>  'exists:user,id',
                        'activity_id'   =>  'exists:activity,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');
        }
        $comment = $this->commentInterface->find($id);
        if (empty($comment)) {
            $this->setError('404', $id);
            return $this->response('404');
        }else{
          if ($this->commentInterface->update($request->all(),$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 ( ) , [ 'user_id' => 'exists:user,id' , 'activity_id' => 'exists:activity,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' ) ; } $ comment = $ this -> commentInterface -> find ( $ id ) ; if ( empty ( $ comment ) ) { $ this -> setError ( '404' , $ id ) ; return $ this -> response ( '404' ) ; } else { if ( $ this -> commentInterface -> update ( $ request -> all ( ) , $ 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 .