regions = $region; } /** * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function index() { $this->authorize('view', 'regions'); $regions = $this->regions->latest('id')->paginate(20); return view('dashboard.regions.index', compact('regions')); } /** * @param UpdateRequest $request * @param Region $region * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function update(UpdateRequest $request, Region $region) { if ($request->isMethod('get')) { $this->authorize('update', 'regions'); $powers = Power::all(); $lang = app()->getLocale(); return view('dashboard.regions.update', compact('region', 'powers', 'lang')); } $this->dispatchSync(UpdateJob::fromRequest($region, $request)); // update or store delivery price if ($request->has('deliveryPrice')) { RegionService::deliveryPrice($region, $request->deliveryPrice); } $this->info(trans('admin.messages.updated')); return redirect()->route('dashboard.regions'); } /** * @param StoreRequest $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function store(StoreRequest $request) { if ($request->isMethod('get')) { $this->authorize('create', 'regions'); $powers = Power::all(); $lang = app()->getLocale(); return view('dashboard.regions.store', compact('powers', 'lang')); } $region = $this->dispatchSync(StoreJob::fromRequest($request)); // store delivery price if ($request->has('deliveryPrice')) { RegionService::deliveryPrice($region, $request->deliveryPrice); } $this->info(trans('admin.messages.created')); return redirect()->route('dashboard.regions'); } /** * @param Region $region * @return \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function delete(Region $region) { $this->authorize('delete', 'regions'); // delete delivery price $region->deliveryPrice()->delete(); $region->delete(); $this->info(trans('admin.messages.deleted')); return redirect()->back(); } }