modules/api/v1/controllers/FavouriteProductController.php
/**
     * Creates a new SearchHistory model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new SearchHistory model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new SearchHistory model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new FavouriteProduct();
        $postData = Yii::$app->request->post();
        $favouriteProduct['FavouriteProduct'] = $postData;
        $favouriteProduct['FavouriteProduct']['user_id'] = Yii::$app->user->identity->id;
        $modelFavourite = FavouriteProduct::find()->where(['product_id' => $favouriteProduct['FavouriteProduct']['product_id'], 'user_id' => Yii::$app->user->identity->id])->one();
        if (!empty($modelFavourite)) {
            throw new BadRequestHttpException('This product has been already favourited!');
        }
        if ($model->load($favouriteProduct) && $model->validate()) {
            $model->save();
        }
        return $model;
    }
public function actionCreate ( ) { $ model = new FavouriteProduct ( ) ; $ postData = Yii :: $ app -> request -> post ( ) ; $ favouriteProduct [ 'FavouriteProduct' ] = $ postData ; $ favouriteProduct [ 'FavouriteProduct' ] [ 'user_id' ] = Yii :: $ app -> user -> identity -> id ; $ modelFavourite = FavouriteProduct :: find ( ) -> where ( [ 'product_id' => $ favouriteProduct [ 'FavouriteProduct' ] [ 'product_id' ] , 'user_id' => Yii :: $ app -> user -> identity -> id ] ) -> one ( ) ; if ( ! empty ( $ modelFavourite ) ) { throw new BadRequestHttpException ( 'This product has been already favourited!' ) ; } if ( $ model -> load ( $ favouriteProduct ) && $ model -> validate ( ) ) { $ model -> save ( ) ; } return $ model ; }
Creates a new SearchHistory model.
Creates a new SearchHistory model .