repository = $store_locator; } /** * Display a list of store_locator. * * @return Response */ public function index(StoreLocatorAdminRequest $request) { $store_locators = $this->repository->setPresenter('\\Energik\\StoreLocator\\Repositories\\Presenter\\StoreLocatorListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this ->theme->prependTitle(trans('store_locator::store_locator.names').' :: '); $view = $this->theme->of('store_locator::admin.store_locator.index')->render(); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('store_locator::store_locator.name')]); $this->responseData = $store_locators['data']; $this->responseMeta = $store_locators['meta']; $this->responseView = $view; $this->responseRedirect = ''; return $this->respond($request); } /** * Display store_locator. * * @param Request $request * @param int $id * * @return Response */ public function show(StoreLocatorAdminRequest $request, StoreLocator $store_locator) { if (!$store_locator->exists) { $this->responseCode = 404; $this->responseMessage = trans('messages.success.notfound', ['Module' => trans('store_locator::store_locator.name')]); $this->responseView = view('store_locator::admin.store_locator.new'); return $this -> respond($request); } Form::populate($store_locator); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('store_locator::store_locator.name')]); $this->responseData = $store_locator; $this->responseView = view('store_locator::admin.store_locator.show', compact('store_locator')); return $this -> respond($request); } /** * Show the form for creating a new store_locator. * * @param Request $request * * @return Response */ public function create(StoreLocatorAdminRequest $request) { $store_locator = $this->repository->newInstance([]); Form::populate($store_locator); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('store_locator::store_locator.name')]); $this->responseData = $store_locator; $this->responseView = view('store_locator::admin.store_locator.create', compact('store_locator')); return $this -> respond($request); } /** * Create new store_locator. * * @param Request $request * * @return Response */ public function store(StoreLocatorAdminRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $store_locator = $this->repository->create($attributes); $this->responseCode = 201; $this->responseMessage = trans('messages.success.created', ['Module' => trans('store_locator::store_locator.name')]); $this->responseData = $store_locator; $this->responseMeta = ''; $this->responseRedirect = trans_url('/admin/store_locator/store_locator/'.$store_locator->getRouteKey()); $this->responseView = view('store_locator::admin.store_locator.create', compact('store_locator')); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); return $this -> respond($request); } } /** * Show store_locator for editing. * * @param Request $request * @param int $id * * @return Response */ public function edit(StoreLocatorAdminRequest $request, StoreLocator $store_locator) { Form::populate($store_locator); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('store_locator::store_locator.name')]); $this->responseData = $store_locator; $this->responseView = view('store_locator::admin.store_locator.edit', compact('store_locator')); return $this -> respond($request); } /** * Update the store_locator. * * @param Request $request * @param int $id * * @return Response */ public function update(StoreLocatorAdminRequest $request, StoreLocator $store_locator) { try { $attributes = $request->all(); $store_locator->update($attributes); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('store_locator::store_locator.name')]); $this->responseData = $store_locator; $this->responseRedirect = trans_url('/admin/store_locator/store_locator/'.$store_locator->getRouteKey()); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/store_locator/store_locator/'.$store_locator->getRouteKey()); return $this -> respond($request); } } /** * Remove the store_locator. * * @param int $id * * @return Response */ public function destroy(StoreLocatorAdminRequest $request, StoreLocator $store_locator) { try { $t = $store_locator->delete(); $this->responseCode = 202; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('store_locator::store_locator.name')]); $this->responseRedirect = trans_url('/admin/store_locator/store_locator/0'); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/store_locator/store_locator/'.$store_locator->getRouteKey()); return $this -> respond($request); } } }