repository = $article; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Cms\Article\Repositories\Criteria\ArticleResourceCriteria::class); } /** * Display a list of article. * * @return Response */ public function index(ArticleRequest $request) { return $this->repository ->setPresenter(\Cms\Article\Repositories\Presenter\ArticlePresenter::class) ->paginate(); } /** * Display article. * * @param Request $request * @param Model $article * * @return Response */ public function show(ArticleRequest $request, Article $article) { return $article->setPresenter(\Cms\Article\Repositories\Presenter\ArticleListPresenter::class); ; } /** * Create new article. * * @param Request $request * * @return Response */ public function store(ArticleRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('article::article.name')]); $code = 204; $status = 'success'; $url = guard_url('article/article/' . $article->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('article/article'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the article. * * @param Request $request * @param Model $article * * @return Response */ public function update(ArticleRequest $request, Article $article) { try { $data = $request->all(); $article->update($data); $message = trans('messages.success.updated', ['Module' => trans('article::article.name')]); $code = 204; $status = 'success'; $url = guard_url('article/article/' . $article->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('article/article/' . $article->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the article. * * @param Model $article * * @return Response */ public function destroy(ArticleRequest $request, Article $article) { try { $article->delete(); $message = trans('messages.success.deleted', ['Module' => trans('article::article.name')]); $code = 202; $status = 'success'; $url = guard_url('article/article/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('article/article/' . $article->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }