app/Http/ApiControllers/ActivityController.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(), [
              'date'          =>  'date',
              'image'         =>  'image',
              'admin_id'      =>  'required|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');
        }
        $activity = $this->activityInterface->find($id);
        if (empty($activity)) {
            $this->setError('404', $id);
            return $this->response('404');
        }else{
          $activity = $request->all();
          if (isset($request->image)) {
              $path = $request->file('image')->getRealPath();
              $img = base64_encode(file_get_contents($path));
              $activity['image'] = $img;
          }
          if (isset($request->type)) {
             $activity['type'] = $this->convertPostType($request->type,0);
          }
            if ($this->activityInterface->update($activity,$id)) {
                event(new ContentCRUDEvent('Update Activity', $request->admin_id, 'Update', 'Updated '. $activity['name']. ' Activity'));
                $this->data(array('updated' =>  1));
                return $this->response('200');
            }else{
                return $this->response('200');
            }
        }
    }
public function update ( Request $ request , $ id ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'date' => 'date' , 'image' => 'image' , 'admin_id' => 'required|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' ) ; } $ activity = $ this -> activityInterface -> find ( $ id ) ; if ( empty ( $ activity ) ) { $ this -> setError ( '404' , $ id ) ; return $ this -> response ( '404' ) ; } else { $ activity = $ request -> all ( ) ; if ( isset ( $ request -> image ) ) { $ path = $ request -> file ( 'image' ) -> getRealPath ( ) ; $ img = base64_encode ( file_get_contents ( $ path ) ) ; $ activity [ 'image' ] = $ img ; } if ( isset ( $ request -> type ) ) { $ activity [ 'type' ] = $ this -> convertPostType ( $ request -> type , 0 ) ; } if ( $ this -> activityInterface -> update ( $ activity , $ id ) ) { event ( new ContentCRUDEvent ( 'Update Activity' , $ request -> admin_id , 'Update' , 'Updated ' . $ activity [ 'name' ] . ' Activity' ) ) ; $ this -> data ( array ( 'updated' => 1 ) ) ; return $ this -> response ( '200' ) ; } else { return $ this -> response ( '200' ) ; } } }
Update the specified resource in storage.
Update the specified resource in storage .