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