validate(['channel_id' => ['required', 'exists:channels,id']]); session(['admin.active_channel_id' => $request->integer('channel_id')]); return back(); } public function index(): View { $channels = Channel::withCount('prefixes')->orderBy('name')->paginate(25); return view('admin::settings.channels.index', compact('channels')); } public function create(): View { $prefixes = Prefix::orderBy('slug')->get(); $channel = new Channel(); return view('admin::settings.channels.form', compact('channel', 'prefixes')); } public function store(Request $request): RedirectResponse { $data = $request->validate([ 'name' => ['required', 'string', 'max:255'], 'hostname' => ['required', 'string', 'max:255', 'unique:channels,hostname'], 'locale' => ['required', 'string', 'max:10'], 'taxonomy_slug' => ['required', 'string', 'max:100'], 'template' => ['required', 'string', 'max:100', 'regex:/^[a-z0-9_-]+$/'], 'meta_title' => ['nullable', 'string', 'max:255'], 'meta_description' => ['nullable', 'string'], 'meta_keywords' => ['nullable', 'string', 'max:255'], 'og_image' => ['nullable', 'string', 'max:255'], 'prefixes' => ['nullable', 'array'], 'prefixes.*' => ['exists:prefixes,id'], ]); $channel = Channel::create($data); $channel->prefixes()->sync($request->input('prefixes', [])); return redirect()->route('admin.settings.channels.index') ->with('success', "Channel \"{$channel->name}\" created."); } public function edit(Channel $channel): View { $prefixes = Prefix::orderBy('slug')->get(); $channel->load('prefixes'); return view('admin::settings.channels.form', compact('channel', 'prefixes')); } public function update(Request $request, Channel $channel): RedirectResponse { $data = $request->validate([ 'name' => ['required', 'string', 'max:255'], 'hostname' => ['required', 'string', 'max:255', "unique:channels,hostname,{$channel->id}"], 'locale' => ['required', 'string', 'max:10'], 'taxonomy_slug' => ['required', 'string', 'max:100'], 'template' => ['required', 'string', 'max:100', 'regex:/^[a-z0-9_-]+$/'], 'meta_title' => ['nullable', 'string', 'max:255'], 'meta_description' => ['nullable', 'string'], 'meta_keywords' => ['nullable', 'string', 'max:255'], 'og_image' => ['nullable', 'string', 'max:255'], 'prefixes' => ['nullable', 'array'], 'prefixes.*' => ['exists:prefixes,id'], ]); $channel->update($data); $channel->prefixes()->sync($request->input('prefixes', [])); return redirect()->route('admin.settings.channels.index') ->with('success', "Channel \"{$channel->name}\" updated."); } public function destroy(Channel $channel): RedirectResponse { $name = $channel->name; $channel->delete(); return redirect()->route('admin.settings.channels.index') ->with('success', "Channel \"{$name}\" deleted."); } }