repository = $notifications; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Labrender\FileRepository\Repositories\Criteria\NotificationsUserCriteria()); parent::__construct(); } /** * Display a list of notifications. * * @return json */ public function index(NotificationsRequest $request) { $notifications = $this->repository ->setPresenter('\\Labrender\\FileRepository\\Repositories\\Presenter\\NotificationsListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); $notifications['code'] = 2000; return response()->json($notifications) ->setStatusCode(200, 'INDEX_SUCCESS'); } /** * Display notifications. * * @param Request $request * @param Model Notifications * * @return Json */ public function show(NotificationsRequest $request, Notifications $notifications) { if ($notifications->exists) { $notifications = $notifications->presenter(); $notifications['code'] = 2001; return response()->json($notifications) ->setStatusCode(200, 'SHOW_SUCCESS');; } else { return response()->json([]) ->setStatusCode(400, 'SHOW_ERROR'); } } /** * Show the form for creating a new notifications. * * @param Request $request * * @return json */ public function create(NotificationsRequest $request, Notifications $notifications) { $notifications = $notifications->presenter(); $notifications['code'] = 2002; return response()->json($notifications) ->setStatusCode(200, 'CREATE_SUCCESS'); } /** * Create new notifications. * * @param Request $request * * @return json */ public function store(NotificationsRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.api'); $notifications = $this->repository->create($attributes); $notifications = $notifications->presenter(); $notifications['code'] = 2004; return response()->json($notifications) ->setStatusCode(201, 'STORE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4004, ])->setStatusCode(400, 'STORE_ERROR'); } } /** * Show notifications for editing. * * @param Request $request * @param Model $notifications * * @return json */ public function edit(NotificationsRequest $request, Notifications $notifications) { if ($notifications->exists) { $notifications = $notifications->presenter(); $notifications['code'] = 2003; return response()-> json($notifications) ->setStatusCode(200, 'EDIT_SUCCESS');; } else { return response()->json([]) ->setStatusCode(400, 'SHOW_ERROR'); } } /** * Update the notifications. * * @param Request $request * @param Model $notifications * * @return json */ public function update(NotificationsRequest $request, Notifications $notifications) { try { $attributes = $request->all(); $notifications->update($attributes); $notifications = $notifications->presenter(); $notifications['code'] = 2005; return response()->json($notifications) ->setStatusCode(201, 'UPDATE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4005, ])->setStatusCode(400, 'UPDATE_ERROR'); } } /** * Remove the notifications. * * @param Request $request * @param Model $notifications * * @return json */ public function destroy(NotificationsRequest $request, Notifications $notifications) { try { $t = $notifications->delete(); return response()->json([ 'message' => trans('messages.success.delete', ['Module' => trans('file_repository::notifications.name')]), 'code' => 2006 ])->setStatusCode(202, 'DESTROY_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4006, ])->setStatusCode(400, 'DESTROY_ERROR'); } } }