fedi-feed-router/app/Http/Controllers/PlatformChannelsController.php

80 lines
2.4 KiB
PHP
Raw Normal View History

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',
'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
PlatformChannel::create($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 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
}
}