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