예제 #1
0
 /**
  * Get category page data.
  *
  * @param int $categoryId
  * @param GetCategoryDataRequest $request
  * @return mixed
  */
 public function getCategory($categoryId, GetCategoryDataRequest $request)
 {
     $category = DB::table('help_center_categories')->where('id', $categoryId)->first();
     $category->articles = HelpCenterArticle::where('category_id', $categoryId)->get();
     $response = new AjaxResponse();
     $response->setSuccessMessage(trans('common.success'));
     $response->addExtraFields(['category' => $category]);
     return response($response->get())->header('Content-Type', 'application/json');
 }
예제 #2
0
 /**
  * Return category articles.
  *
  * @param int $categoryId
  * @return array
  */
 public static function getCategoryArticles($categoryId)
 {
     $categoryArticles = [];
     $results = HelpCenterArticle::where('category_id', $categoryId)->get();
     foreach ($results as $result) {
         $categoryArticles[] = $result;
     }
     return $categoryArticles;
 }
예제 #3
0
 /**
  * Edit article title and content.
  *
  * @param int $categoryId
  * @param EditArticleRequest $request
  * @return mixed
  */
 public function editArticle($categoryId, EditArticleRequest $request)
 {
     $response = new AjaxResponse();
     $category = HelpCenterCategory::where('id', $categoryId)->first();
     if (!$category) {
         $response->setFailMessage(trans('help_center.category_not_found'));
         return response($response->get(), $response->getDefaultErrorResponseCode())->header('Content-Type', 'application/json');
     }
     // Edit article
     $article = HelpCenterArticle::find($request->get('article_id'));
     $article->title = $request->get('article_title');
     $article->content = $request->get('article_content');
     $article->save();
     // Get updated version of articles
     $extraFields = [];
     $articles = HelpCenterManagerHelper::getCategoryArticles($categoryId);
     if (count($articles)) {
         $extraFields['articles'] = $articles;
     }
     $response->setSuccessMessage(trans('help_center.article_updated'));
     $response->addExtraFields($extraFields);
     return response($response->get())->header('Content-Type', 'application/json');
 }