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