repository = $news_category; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepie\News\Repositories\Criteria\NewsCategoryResourceCriteria::class); } /** * Display a list of news_category. * * @return Response */ public function index(NewsCategoryRequest $request) { return $this->repository ->setPresenter(\Litepie\News\Repositories\Presenter\NewsCategoryPresenter::class) ->paginate(); } /** * Display news_category. * * @param Request $request * @param Model $news_category * * @return Response */ public function show(NewsCategoryRequest $request, NewsCategory $news_category) { return $news_category->setPresenter(\Litepie\News\Repositories\Presenter\NewsCategoryListPresenter::class); ; } /** * Create new news_category. * * @param Request $request * * @return Response */ public function store(NewsCategoryRequest $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('news::news_category.name')]); $code = 204; $status = 'success'; $url = guard_url('news/news_category/' . $news_category->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('news/news_category'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the news_category. * * @param Request $request * @param Model $news_category * * @return Response */ public function update(NewsCategoryRequest $request, NewsCategory $news_category) { try { $data = $request->all(); $news_category->update($data); $message = trans('messages.success.updated', ['Module' => trans('news::news_category.name')]); $code = 204; $status = 'success'; $url = guard_url('news/news_category/' . $news_category->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('news/news_category/' . $news_category->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the news_category. * * @param Model $news_category * * @return Response */ public function destroy(NewsCategoryRequest $request, NewsCategory $news_category) { try { $news_category->delete(); $message = trans('messages.success.deleted', ['Module' => trans('news::news_category.name')]); $code = 202; $status = 'success'; $url = guard_url('news/news_category/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('news/news_category/' . $news_category->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); } }