authorizeResource(StaticPage::class); } /** * Show the form for editing the specified resource. * * @param \App\Models\StaticPage $static_page * @return \Illuminate\Contracts\View\View */ public function edit(StaticPage $static_page): \Illuminate\Contracts\View\View { return view('bo.pages.static_pages.edit', ['staticPageModel' => $static_page]); } /** * Update the specified resource in storage. * * @param \App\Http\Requests\Bo\StaticPages\UpdateStaticPageRequest $request * @param \App\Models\StaticPage $static_page * @return \Illuminate\Http\RedirectResponse */ public function update(UpdateStaticPageRequest $request, StaticPage $static_page): \Illuminate\Http\RedirectResponse { return DB::transaction(function () use ($request, $static_page) { $static_page->fill(array_replace_recursive( $static_page->getFillableFields($static_page), $request->validated() )); if ($static_page->saveOrFail()) { return redirect()->route('bo.static_pages.edit', $static_page) ->with('success', trans('crud.messages.has_been_updated', [ 'model' => Str::ucfirst(\trans_choice('models.classes.static_page', 1)) ])); } return redirect()->route('bo.static_pages.edit', $static_page) ->with('error', trans('crud.messages.cannot_be_updated', [ 'model' => Str::ucfirst(\trans_choice('models.classes.static_page', 1)) ])); }); } /** * Display the common section edit form for all breeding static pages. * * @return \Illuminate\Contracts\View\View */ public function getCommonSection(): \Illuminate\Contracts\View\View { $commonSection = StaticPage::whereIn('type', StaticPageType::getBreedingValues()) ->get() ->map(fn($page) => $page->data['common_section'] ?? null) ->filter() ->first(); return view('bo.pages.static_pages.common_section.edit', [ 'commonSection' => $commonSection, ]); } /** * Update the common section for all breeding static pages. * * @param \App\Http\Requests\Bo\StaticPage\UpdateCommonSectionRequest $request * @return \Illuminate\Http\RedirectResponse */ public function updateCommonSection(UpdateCommonSectionRequest $request): RedirectResponse { $pages = StaticPage::whereIn('type', StaticPageType::getBreedingValues())->get(); try { DB::transaction(function () use ($pages, $request) { foreach ($pages as $page) { $data = $page->data ?? []; $data['common_section'] = [ 'title' => $request->validated('title'), 'content' => $request->validated('content'), ]; $page->data = $data; $page->saveOrFail(); } }); } catch (Throwable $e) { return redirect() ->back() ->withInput() ->with('error', __('crud.messages.cannot_be_updated', [ 'model' => Str::ucfirst(__('validation.custom.common_section_part'))])); } return redirect() ->route('bo.static_page.sections.edit') ->with('success', __('crud.messages.has_been_updated', [ 'model' => Str::ucfirst(__('validation.custom.common_section_part'))])); } }