Optimize academy
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Moderation;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\StaffApplication;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
final class StaffApplicationsController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$filters = [
|
||||
'q' => trim((string) $request->query('q', '')),
|
||||
'topic' => trim((string) $request->query('topic', 'all')),
|
||||
];
|
||||
|
||||
$query = StaffApplication::query()->latest('created_at');
|
||||
|
||||
if ($filters['q'] !== '') {
|
||||
$search = $filters['q'];
|
||||
$query->where(function ($builder) use ($search): void {
|
||||
$builder
|
||||
->where('name', 'like', '%' . $search . '%')
|
||||
->orWhere('email', 'like', '%' . $search . '%')
|
||||
->orWhere('role', 'like', '%' . $search . '%')
|
||||
->orWhere('message', 'like', '%' . $search . '%');
|
||||
});
|
||||
}
|
||||
|
||||
if ($filters['topic'] !== '' && $filters['topic'] !== 'all') {
|
||||
$query->where('topic', $filters['topic']);
|
||||
}
|
||||
|
||||
$items = $query
|
||||
->paginate(20)
|
||||
->withQueryString()
|
||||
->through(fn (StaffApplication $application): array => $this->serializeApplication($application));
|
||||
|
||||
$stats = [
|
||||
'total' => StaffApplication::query()->count(),
|
||||
'applications' => StaffApplication::query()->where('topic', 'application')->count(),
|
||||
'bug' => StaffApplication::query()->where('topic', 'bug')->count(),
|
||||
'contact' => StaffApplication::query()->where('topic', 'contact')->count(),
|
||||
'other' => StaffApplication::query()->whereNotIn('topic', ['application', 'bug', 'contact'])->count(),
|
||||
];
|
||||
|
||||
$topics = StaffApplication::query()
|
||||
->select('topic')
|
||||
->distinct()
|
||||
->orderBy('topic')
|
||||
->pluck('topic')
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return Inertia::render('Moderation/StaffApplications/Index', [
|
||||
'title' => 'Staff Applications',
|
||||
'items' => $items,
|
||||
'filters' => $filters,
|
||||
'stats' => $stats,
|
||||
'topics' => $topics,
|
||||
'endpoints' => [
|
||||
'index' => route('admin.staff-applications.index'),
|
||||
],
|
||||
])->rootView('moderation');
|
||||
}
|
||||
|
||||
public function show(StaffApplication $staffApplication): Response
|
||||
{
|
||||
return Inertia::render('Moderation/StaffApplications/Show', [
|
||||
'title' => 'Staff Application',
|
||||
'item' => $this->serializeApplication($staffApplication, true),
|
||||
'backUrl' => route('admin.staff-applications.index'),
|
||||
])->rootView('moderation');
|
||||
}
|
||||
|
||||
private function serializeApplication(StaffApplication $application, bool $detailed = false): array
|
||||
{
|
||||
return [
|
||||
'id' => (string) $application->id,
|
||||
'topic' => (string) ($application->topic ?: 'contact'),
|
||||
'name' => (string) ($application->name ?: 'Unknown'),
|
||||
'email' => (string) ($application->email ?: ''),
|
||||
'role' => $application->role,
|
||||
'portfolio' => $application->portfolio,
|
||||
'message' => $application->message,
|
||||
'ip' => $application->ip,
|
||||
'user_agent' => $application->user_agent,
|
||||
'created_at' => optional($application->created_at)?->toIso8601String(),
|
||||
'payload' => $detailed ? ($application->payload ?? []) : [],
|
||||
'show_url' => route('admin.staff-applications.show', ['staffApplication' => $application]),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user