80 lines
2.4 KiB
PHP
80 lines
2.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
|
||
|
|
use App\Models\Community;
|
||
|
|
use App\Models\PlatformInstance;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Contracts\View\View;
|
||
|
|
use Illuminate\Http\RedirectResponse;
|
||
|
|
|
||
|
|
class CommunitiesController extends Controller
|
||
|
|
{
|
||
|
|
public function index(): View
|
||
|
|
{
|
||
|
|
$communities = Community::with('platformInstance')
|
||
|
|
->orderBy('platform_instance_id')
|
||
|
|
->orderBy('name')
|
||
|
|
->get();
|
||
|
|
|
||
|
|
return view('pages.communities.index', compact('communities'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function create(): View
|
||
|
|
{
|
||
|
|
$instances = PlatformInstance::where('is_active', true)
|
||
|
|
->orderBy('name')
|
||
|
|
->get();
|
||
|
|
|
||
|
|
return view('pages.communities.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',
|
||
|
|
'community_id' => 'required|string|max:255',
|
||
|
|
'description' => 'nullable|string',
|
||
|
|
]);
|
||
|
|
|
||
|
|
Community::create($validated);
|
||
|
|
|
||
|
|
return redirect()->route('communities.index')
|
||
|
|
->with('success', 'Community created successfully!');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function edit(Community $community): View
|
||
|
|
{
|
||
|
|
$instances = PlatformInstance::where('is_active', true)
|
||
|
|
->orderBy('name')
|
||
|
|
->get();
|
||
|
|
|
||
|
|
return view('pages.communities.edit', compact('community', 'instances'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function update(Request $request, Community $community): RedirectResponse
|
||
|
|
{
|
||
|
|
$validated = $request->validate([
|
||
|
|
'platform_instance_id' => 'required|exists:platform_instances,id',
|
||
|
|
'name' => 'required|string|max:255',
|
||
|
|
'display_name' => 'required|string|max:255',
|
||
|
|
'community_id' => 'required|string|max:255',
|
||
|
|
'description' => 'nullable|string',
|
||
|
|
]);
|
||
|
|
|
||
|
|
$community->update($validated);
|
||
|
|
|
||
|
|
return redirect()->route('communities.index')
|
||
|
|
->with('success', 'Community updated successfully!');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function destroy(Community $community): RedirectResponse
|
||
|
|
{
|
||
|
|
$community->delete();
|
||
|
|
|
||
|
|
return redirect()->route('communities.index')
|
||
|
|
->with('success', 'Community deleted successfully!');
|
||
|
|
}
|
||
|
|
}
|