2025-07-05 02:19:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
use App\Models\PlatformChannel;
|
2025-07-05 02:19:59 +02:00
|
|
|
use App\Models\PlatformInstance;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
class PlatformChannelsController extends Controller
|
2025-07-05 02:19:59 +02:00
|
|
|
{
|
|
|
|
|
public function index(): View
|
|
|
|
|
{
|
2025-07-05 02:29:50 +02:00
|
|
|
$channels = PlatformChannel::with('platformInstance')
|
2025-07-05 02:19:59 +02:00
|
|
|
->orderBy('platform_instance_id')
|
|
|
|
|
->orderBy('name')
|
|
|
|
|
->get();
|
|
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
return view('pages.channels.index', compact('channels'));
|
2025-07-05 02:19:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create(): View
|
|
|
|
|
{
|
|
|
|
|
$instances = PlatformInstance::where('is_active', true)
|
|
|
|
|
->orderBy('name')
|
|
|
|
|
->get();
|
|
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
return view('pages.channels.create', compact('instances'));
|
2025-07-05 02:19:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function store(Request $request): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$validated = $request->validate([
|
|
|
|
|
'platform_instance_id' => 'required|exists:platform_instances,id',
|
|
|
|
|
'name' => 'required|string|max:255',
|
2025-07-06 11:22:53 +02:00
|
|
|
'display_name' => 'nullable|string|max:255',
|
|
|
|
|
'channel_id' => 'nullable|string|max:255',
|
2025-07-05 02:19:59 +02:00
|
|
|
'description' => 'nullable|string',
|
2025-07-06 11:22:53 +02:00
|
|
|
'language_id' => 'required|exists:languages,id',
|
|
|
|
|
'is_active' => 'boolean',
|
2025-07-05 02:19:59 +02:00
|
|
|
]);
|
|
|
|
|
|
2025-07-06 11:22:53 +02:00
|
|
|
// 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'];
|
|
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
PlatformChannel::create($validated);
|
2025-07-05 02:19:59 +02:00
|
|
|
|
2025-07-06 11:22:53 +02:00
|
|
|
// 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!');
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
return redirect()->route('channels.index')
|
|
|
|
|
->with('success', 'Channel created successfully!');
|
2025-07-05 02:19:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
public function edit(PlatformChannel $channel): View
|
2025-07-05 02:19:59 +02:00
|
|
|
{
|
|
|
|
|
$instances = PlatformInstance::where('is_active', true)
|
|
|
|
|
->orderBy('name')
|
|
|
|
|
->get();
|
|
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
return view('pages.channels.edit', compact('channel', 'instances'));
|
2025-07-05 02:19:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
public function update(Request $request, PlatformChannel $channel): RedirectResponse
|
2025-07-05 02:19:59 +02:00
|
|
|
{
|
|
|
|
|
$validated = $request->validate([
|
|
|
|
|
'platform_instance_id' => 'required|exists:platform_instances,id',
|
|
|
|
|
'name' => 'required|string|max:255',
|
|
|
|
|
'display_name' => 'required|string|max:255',
|
2025-07-05 02:29:50 +02:00
|
|
|
'channel_id' => 'required|string|max:255',
|
2025-07-05 02:19:59 +02:00
|
|
|
'description' => 'nullable|string',
|
|
|
|
|
]);
|
|
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
$channel->update($validated);
|
2025-07-05 02:19:59 +02:00
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
return redirect()->route('channels.index')
|
|
|
|
|
->with('success', 'Channel updated successfully!');
|
2025-07-05 02:19:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
public function destroy(PlatformChannel $channel): RedirectResponse
|
2025-07-05 02:19:59 +02:00
|
|
|
{
|
2025-07-05 02:29:50 +02:00
|
|
|
$channel->delete();
|
2025-07-05 02:19:59 +02:00
|
|
|
|
2025-07-05 02:29:50 +02:00
|
|
|
return redirect()->route('channels.index')
|
|
|
|
|
->with('success', 'Channel deleted successfully!');
|
2025-07-05 02:19:59 +02:00
|
|
|
}
|
|
|
|
|
}
|