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