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