repository = $service; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Boomee\Service\Repositories\Criteria\ServiceResourceCriteria::class); } /** * Display a list of service. * * @return Response */ public function index(ServiceRequest $request) { return $this->repository ->setPresenter(\Boomee\Service\Repositories\Presenter\ServicePresenter::class) ->paginate(); } /** * Display service. * * @param Request $request * @param Model $service * * @return Response */ public function show(ServiceRequest $request, Service $service) { return $service->setPresenter(\Boomee\Service\Repositories\Presenter\ServiceListPresenter::class); ; } /** * Create new service. * * @param Request $request * * @return Response */ public function store(ServiceRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('service::service.name')]); $code = 204; $status = 'success'; $url = guard_url('service/service/' . $service->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('service/service'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the service. * * @param Request $request * @param Model $service * * @return Response */ public function update(ServiceRequest $request, Service $service) { try { $data = $request->all(); $service->update($data); $message = trans('messages.success.updated', ['Module' => trans('service::service.name')]); $code = 204; $status = 'success'; $url = guard_url('service/service/' . $service->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('service/service/' . $service->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the service. * * @param Model $service * * @return Response */ public function destroy(ServiceRequest $request, Service $service) { try { $service->delete(); $message = trans('messages.success.deleted', ['Module' => trans('service::service.name')]); $code = 202; $status = 'success'; $url = guard_url('service/service/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('service/service/' . $service->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }