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