You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.5 KiB

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Competition;
use Illuminate\Http\JsonResponse;
class PublicCompetitionController extends Controller
{
public function showBySlug(string $slug): JsonResponse
{
$competition = Competition::query()
->where('slug', $slug)
->where('published', true)
->with([
'formSchema',
'tracks' => function ($q) {
$q->where('is_enabled', true)->orderBy('sort')->orderBy('id');
},
])
->firstOrFail();
return response()->json([
'id' => $competition->id,
'slug' => $competition->slug,
'name' => $competition->name,
'description' => $competition->description,
'pledge_content_html' => $competition->pledge_content_html,
'status' => $competition->status,
'signup_open_at' => $competition->signup_open_at?->toIso8601String(),
'signup_close_at' => $competition->signup_close_at?->toIso8601String(),
'branding_json' => $competition->branding_json ?? new \stdClass,
'signup_form_schema' => $competition->formSchema?->schema_json ?? [],
'tracks' => $competition->tracks->map(fn ($t) => [
'track_code' => $t->track_code,
'title' => $t->title,
'description' => $t->description,
'sort' => $t->sort,
]),
]);
}
}