repository = $state; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Classifieds\Location\Repositories\Criteria\StateResourceCriteria::class); } /** * Display a list of state. * * @return Response */ public function index(StateRequest $request) { return $this->repository ->setPresenter(\Classifieds\Location\Repositories\Presenter\StatePresenter::class) ->paginate(); } /** * Display state. * * @param Request $request * @param Model $state * * @return Response */ public function show(StateRequest $request, State $state) { return $state->setPresenter(\Classifieds\Location\Repositories\Presenter\StateListPresenter::class); ; } /** * Create new state. * * @param Request $request * * @return Response */ public function store(StateRequest $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('location::state.name')]); $code = 204; $status = 'success'; $url = guard_url('location/state/' . $state->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('location/state'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the state. * * @param Request $request * @param Model $state * * @return Response */ public function update(StateRequest $request, State $state) { try { $data = $request->all(); $state->update($data); $message = trans('messages.success.updated', ['Module' => trans('location::state.name')]); $code = 204; $status = 'success'; $url = guard_url('location/state/' . $state->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('location/state/' . $state->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the state. * * @param Model $state * * @return Response */ public function destroy(StateRequest $request, State $state) { try { $state->delete(); $message = trans('messages.success.deleted', ['Module' => trans('location::state.name')]); $code = 202; $status = 'success'; $url = guard_url('location/state/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('location/state/' . $state->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); } }