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