repository = $facility; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Assetdocs\Facility\Repositories\Criteria\FacilityUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(FacilityRequest $request) { $facilities = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('facility::facility.names')); return $this->theme->of('facility::user.facility.index', compact('facilities'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Facility $facility * * @return Response */ public function show(FacilityRequest $request, Facility $facility) { Form::populate($facility); return $this->theme->of('facility::user.facility.show', compact('facility'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(FacilityRequest $request) { $facility = $this->repository->newInstance([]); Form::populate($facility); $this->theme->prependTitle(trans('facility::facility.names')); return $this->theme->of('facility::user.facility.create', compact('facility'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(FacilityRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $facility = $this->repository->create($attributes); return redirect(trans_url('/user/facility/facility')) -> with('message', trans('messages.success.created', ['Module' => trans('facility::facility.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Facility $facility * * @return Response */ public function edit(FacilityRequest $request, Facility $facility) { Form::populate($facility); $this->theme->prependTitle(trans('facility::facility.names')); return $this->theme->of('facility::user.facility.edit', compact('facility'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Facility $facility * * @return Response */ public function update(FacilityRequest $request, Facility $facility) { try { $this->repository->update($request->all(), $facility->getRouteKey()); return redirect(trans_url('/user/facility/facility')) ->with('message', trans('messages.success.updated', ['Module' => trans('facility::facility.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(FacilityRequest $request, Facility $facility) { try { $this->repository->delete($facility->getRouteKey()); return redirect(trans_url('/user/facility/facility')) ->with('message', trans('messages.success.deleted', ['Module' => trans('facility::facility.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }