get(); return view('admin.pages.index', compact('pages')); } public function edit(Page $page): View { // Текущие секции страницы с загруженным блоком $sections = PageSection::where('page_id', $page->id) ->orderBy('sort_order') ->with('block') ->get(); // Блоки, которые ещё не добавлены на страницу (type=block секции) $usedBlockIds = $sections->where('type', 'block')->pluck('block_id')->filter()->all(); $availableBlocks = Block::where('is_active', true) ->whereNotIn('id', $usedBlockIds) ->orderBy('title') ->get(); return view('admin.pages.edit', compact('page', 'sections', 'availableBlocks')); } public function update(Request $request, Page $page): RedirectResponse { $data = $request->validate([ 'title' => 'required|string|max:255', 'content' => 'nullable|string', 'meta_title' => 'nullable|string|max:255', 'meta_description' => 'nullable|string|max:500', 'is_active' => 'nullable|boolean', ]); $data['is_active'] = $request->boolean('is_active'); $page->update($data); // Сбрасываем кеш публичной страницы после сохранения Cache::forget('page.'.$page->slug); return redirect()->route('admin.pages.index') ->with('success', 'Страница «'.$page->title.'» сохранена.'); } }