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