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