orderBy('platform_instance_id') ->orderBy('name') ->get(); return ViewFacade::make('pages.channels.index', compact('channels')); } public function create(): View { $instances = PlatformInstance::where('is_active', true) ->orderBy('name') ->get(); return ViewFacade::make('pages.channels.create', compact('instances')); } public function store(Request $request): RedirectResponse { $validated = $request->validate([ 'platform_instance_id' => 'required|exists:platform_instances,id', 'name' => 'required|string|max:255', 'display_name' => 'nullable|string|max:255', 'channel_id' => 'nullable|string|max:255', 'description' => 'nullable|string', 'language_id' => 'required|exists:languages,id', 'is_active' => 'boolean', ]); // Default is_active to true if not provided $validated['is_active'] = $validated['is_active'] ?? true; // Set display_name to name if not provided $validated['display_name'] = $validated['display_name'] ?? $validated['name']; PlatformChannel::create($validated); // Check if there's a redirect_to parameter for onboarding flow $redirectTo = $request->input('redirect_to'); if ($redirectTo) { return redirect($redirectTo) ->with('success', 'Channel created successfully!'); } return redirect()->route('channels.index') ->with('success', 'Channel created successfully!'); } public function show(PlatformChannel $channel): View { $channel->load(['platformInstance', 'feeds']); return ViewFacade::make('pages.channels.show', compact('channel')); } public function edit(PlatformChannel $channel): View { $instances = PlatformInstance::where('is_active', true) ->orderBy('name') ->get(); return ViewFacade::make('pages.channels.edit', compact('channel', 'instances')); } public function update(Request $request, PlatformChannel $channel): RedirectResponse { $validated = $request->validate([ 'platform_instance_id' => 'required|exists:platform_instances,id', 'name' => 'required|string|max:255', 'display_name' => 'nullable|string|max:255', 'channel_id' => 'nullable|string|max:255', 'description' => 'nullable|string', 'language_id' => 'required|exists:languages,id', 'is_active' => 'boolean', ]); $channel->update($validated); return redirect()->route('channels.index') ->with('success', 'Channel updated successfully!'); } public function destroy(PlatformChannel $channel): RedirectResponse { $channel->delete(); return redirect()->route('channels.index') ->with('success', 'Channel deleted successfully!'); } public function toggle(PlatformChannel $channel): RedirectResponse { $newStatus = !$channel->is_active; $channel->update(['is_active' => $newStatus]); $status = $newStatus ? 'activated' : 'deactivated'; return redirect()->route('channels.index') ->with('success', "Channel {$status} successfully!"); } }