repository = $notifications; parent::__construct(); } /** * Display a list of notifications. * * @return Response */ public function index(NotificationsRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('file_repository::notifications.names').' :: '); return $this->theme->of('file_repository::admin.notifications.index')->render(); } /** * Display a list of notifications. * * @return Response */ public function getJson(NotificationsRequest $request) { $pageLimit = $request->input('pageLimit'); $notifications = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Labrender\\FileRepository\\Repositories\\Presenter\\NotificationsListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $notifications['recordsTotal'] = $notifications['meta']['pagination']['total']; $notifications['recordsFiltered'] = $notifications['meta']['pagination']['total']; $notifications['request'] = $request->all(); return response()->json($notifications, 200); } /** * Display notifications. * * @param Request $request * @param Model $notifications * * @return Response */ public function show(NotificationsRequest $request, Notifications $notifications) { if (!$notifications->exists) { return response()->view('file_repository::admin.notifications.new', compact('notifications')); } Form::populate($notifications); return response()->view('file_repository::admin.notifications.show', compact('notifications')); } /** * Show the form for creating a new notifications. * * @param Request $request * * @return Response */ public function create(NotificationsRequest $request) { $notifications = $this->repository->newInstance([]); Form::populate($notifications); return response()->view('file_repository::admin.notifications.create', compact('notifications')); } /** * Create new notifications. * * @param Request $request * * @return Response */ public function store(NotificationsRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $notifications = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('file_repository::notifications.name')]), 'code' => 204, 'redirect' => trans_url('/admin/file_repository/notifications/'.$notifications->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show notifications for editing. * * @param Request $request * @param Model $notifications * * @return Response */ public function edit(NotificationsRequest $request, Notifications $notifications) { Form::populate($notifications); return response()->view('file_repository::admin.notifications.edit', compact('notifications')); } /** * Update the notifications. * * @param Request $request * @param Model $notifications * * @return Response */ public function update(NotificationsRequest $request, Notifications $notifications) { try { $attributes = $request->all(); $notifications->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('file_repository::notifications.name')]), 'code' => 204, 'redirect' => trans_url('/admin/file_repository/notifications/'.$notifications->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/file_repository/notifications/'.$notifications->getRouteKey()), ], 400); } } /** * Remove the notifications. * * @param Model $notifications * * @return Response */ public function destroy(NotificationsRequest $request, Notifications $notifications) { try { $t = $notifications->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('file_repository::notifications.name')]), 'code' => 202, 'redirect' => trans_url('/admin/file_repository/notifications/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/file_repository/notifications/'.$notifications->getRouteKey()), ], 400); } } }