|
|
|
|
@ -5,17 +5,24 @@ namespace App\Http\Controllers\Api;
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Competition;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
|
|
|
|
|
|
class PublicCompetitionController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function active(): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$competition = Competition::query()
|
|
|
|
|
->where('published', true)
|
|
|
|
|
->whereIn('status', ['published', 'signup_open'])
|
|
|
|
|
->orderByDesc('signup_open_at')
|
|
|
|
|
->orderByDesc('id')
|
|
|
|
|
->firstOrFail();
|
|
|
|
|
$query = Competition::query();
|
|
|
|
|
if (Schema::hasColumn('competitions', 'published')) {
|
|
|
|
|
$query->where('published', true);
|
|
|
|
|
}
|
|
|
|
|
if (Schema::hasColumn('competitions', 'status')) {
|
|
|
|
|
$query->whereIn('status', ['published', 'signup_open']);
|
|
|
|
|
}
|
|
|
|
|
if (Schema::hasColumn('competitions', 'signup_open_at')) {
|
|
|
|
|
$query->orderByDesc('signup_open_at');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$competition = $query->orderByDesc('id')->firstOrFail();
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'id' => $competition->id,
|
|
|
|
|
|