app/Http/ApiControllers/CourseController.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',
                'image'     =>  'required',
                '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 = $request->all();
         $path = $request->file('image')->getRealPath();
         $img = base64_encode(file_get_contents($path));
         $course['image'] = $img;
         $result = $this->courseInterface->store($course);
         if (isset($result)) {
             event(new ContentCRUDEvent('Create Course', $request->admin_id, 'Create', 'Made '. $request->name. ' Course'));
             $this->data(array('id' =>  $result));
         }
         return $this->response('201');
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'name' => 'required' , 'image' => 'required' , '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 = $ request -> all ( ) ; $ path = $ request -> file ( 'image' ) -> getRealPath ( ) ; $ img = base64_encode ( file_get_contents ( $ path ) ) ; $ course [ 'image' ] = $ img ; $ result = $ this -> courseInterface -> store ( $ course ) ; if ( isset ( $ result ) ) { event ( new ContentCRUDEvent ( 'Create Course' , $ request -> admin_id , 'Create' , 'Made ' . $ request -> name . ' Course' ) ) ; $ this -> data ( array ( 'id' => $ result ) ) ; } return $ this -> response ( '201' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .