app/Http/ApiControllers/LikeController.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(), [
                'user_id'       =>  'required|exists:user,id',
                'activity_id'   =>  'required|exists:activity,id'
            ]);
        $like = $request->all();
        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]);
            $result = $this->likeInterface->isliked($like['activity_id'], $like['user_id']);
            $this->data($result);
            return $this->response('400');
        }
        $result = $this->likeInterface->isliked($like['activity_id'], $like['user_id']);
        if ($result['liked'] == false) {
            $this->likeInterface->store($like);
        }
         if (isset($result)) {
            $this->data($result);
         }
         return $this->response('201');
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'user_id' => 'required|exists:user,id' , 'activity_id' => 'required|exists:activity,id' ] ) ; $ like = $ request -> all ( ) ; 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 ] ) ; $ result = $ this -> likeInterface -> isliked ( $ like [ 'activity_id' ] , $ like [ 'user_id' ] ) ; $ this -> data ( $ result ) ; return $ this -> response ( '400' ) ; } $ result = $ this -> likeInterface -> isliked ( $ like [ 'activity_id' ] , $ like [ 'user_id' ] ) ; if ( $ result [ 'liked' ] == false ) { $ this -> likeInterface -> store ( $ like ) ; } if ( isset ( $ result ) ) { $ this -> data ( $ result ) ; } return $ this -> response ( '201' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .