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