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