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

80 lines
No EOL
2.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\PlatformChannel;
use App\Models\PlatformInstance;
use Illuminate\Http\Request;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
class PlatformChannelsController extends Controller
{
public function index(): View
{
$channels = PlatformChannel::with('platformInstance')
->orderBy('platform_instance_id')
->orderBy('name')
->get();
return view('pages.channels.index', compact('channels'));
}
public function create(): View
{
$instances = PlatformInstance::where('is_active', true)
->orderBy('name')
->get();
return view('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' => 'required|string|max:255',
'channel_id' => 'required|string|max:255',
'description' => 'nullable|string',
]);
PlatformChannel::create($validated);
return redirect()->route('channels.index')
->with('success', 'Channel created successfully!');
}
public function edit(PlatformChannel $channel): View
{
$instances = PlatformInstance::where('is_active', true)
->orderBy('name')
->get();
return view('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' => 'required|string|max:255',
'channel_id' => 'required|string|max:255',
'description' => 'nullable|string',
]);
$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!');
}
}