repository = $latest_news; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\News\Repositories\Criteria\LatestNewsResourceCriteria::class); } /** * Display a list of latest_news. * * @return Response */ public function index(LatestNewsRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litecms\News\Repositories\Presenter\LatestNewsPresenter::class) ->$function(); } $latest_news = $this->repository->paginate(); return $this->response->title(trans('news::latest_news.names')) ->view('news::latest_news.index', true) ->data(compact('latest_news')) ->output(); } /** * Display latest_news. * * @param Request $request * @param Model $latest_news * * @return Response */ public function show(LatestNewsRequest $request, LatestNews $latest_news) { if ($latest_news->exists) { $view = 'news::latest_news.show'; } else { $view = 'news::latest_news.new'; } return $this->response->title(trans('app.view') . ' ' . trans('news::latest_news.name')) ->data(compact('latest_news')) ->view($view, true) ->output(); } /** * Show the form for creating a new latest_news. * * @param Request $request * * @return Response */ public function create(LatestNewsRequest $request) { $latest_news = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('news::latest_news.name')) ->view('news::latest_news.create', true) ->data(compact('latest_news')) ->output(); } /** * Create new latest_news. * * @param Request $request * * @return Response */ public function store(LatestNewsRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $latest_news = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('news::latest_news.name')])) ->code(204) ->status('success') ->url(guard_url('news/latest_news/' . $latest_news->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/news/latest_news')) ->redirect(); } } /** * Show latest_news for editing. * * @param Request $request * @param Model $latest_news * * @return Response */ public function edit(LatestNewsRequest $request, LatestNews $latest_news) { return $this->response->title(trans('app.edit') . ' ' . trans('news::latest_news.name')) ->view('news::latest_news.edit', true) ->data(compact('latest_news')) ->output(); } /** * Update the latest_news. * * @param Request $request * @param Model $latest_news * * @return Response */ public function update(LatestNewsRequest $request, LatestNews $latest_news) { try { $attributes = $request->all(); $latest_news->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('news::latest_news.name')])) ->code(204) ->status('success') ->url(guard_url('news/latest_news/' . $latest_news->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('news/latest_news/' . $latest_news->getRouteKey())) ->redirect(); } } /** * Remove the latest_news. * * @param Model $latest_news * * @return Response */ public function destroy(LatestNewsRequest $request, LatestNews $latest_news) { try { $latest_news->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('news::latest_news.name')])) ->code(202) ->status('success') ->url(guard_url('news/latest_news/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('news/latest_news/' . $latest_news->getRouteKey())) ->redirect(); } } /** * Remove multiple latest_news. * * @param Model $latest_news * * @return Response */ public function delete(LatestNewsRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('news::latest_news.name')])) ->status("success") ->code(202) ->url(guard_url('news/latest_news')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/news/latest_news')) ->redirect(); } } /** * Restore deleted latest_news. * * @param Model $latest_news * * @return Response */ public function restore(LatestNewsRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('news::latest_news.name')])) ->status("success") ->code(202) ->url(guard_url('/news/latest_news')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/news/latest_news/')) ->redirect(); } } }