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