init
This commit is contained in:
commit
d61b3651ba
|
|
@ -0,0 +1,18 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_size = 2
|
||||
|
||||
[docker-compose.yml]
|
||||
indent_size = 4
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
APP_NAME=Laravel
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
CORS_ALLOWED_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
|
||||
CORS_SUPPORTS_CREDENTIALS=false
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=pgsql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=5432
|
||||
DB_DATABASE=pxg_2026
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=file
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=mailpit
|
||||
MAIL_PORT=1025
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS="hello@example.com"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
PUSHER_APP_ID=
|
||||
PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_HOST=
|
||||
PUSHER_PORT=443
|
||||
PUSHER_SCHEME=https
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
* text=auto eol=lf
|
||||
|
||||
*.blade.php diff=html
|
||||
*.css diff=css
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
*.php diff=php
|
||||
|
||||
/.github export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
.styleci.yml export-ignore
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/.phpunit.cache
|
||||
/node_modules
|
||||
/public/build
|
||||
/public/hot
|
||||
/public/storage
|
||||
/storage/*.key
|
||||
/vendor
|
||||
.env
|
||||
.env.backup
|
||||
.env.production
|
||||
.phpunit.result.cache
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
auth.json
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
/.fleet
|
||||
/.idea
|
||||
/.vscode
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
## Integration notes
|
||||
|
||||
1) Copy files into an existing Laravel project.
|
||||
2) Add `config/pxg.php`.
|
||||
3) Register `App\Providers\PxgServiceProvider` in `config/app.php` providers array (Laravel 10) if not auto-discovered.
|
||||
|
||||
4) Register command:
|
||||
- Ensure `app/Console/Kernel.php` loads commands folder (default).
|
||||
- Command: `php artisan pxg:seed-flights --event=1`
|
||||
|
||||
5) CORS:
|
||||
- Ensure your Laravel CORS allows the Vue origin (e.g., localhost:5173).
|
||||
|
||||
|
||||
7) Scheduler pairing (recommended):
|
||||
- Add Laravel scheduler cron on server:
|
||||
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
|
||||
- Scheduler will run `pxg:pairing-tick` every minute.
|
||||
- You can also run manually: `php artisan pxg:pairing-tick --event=1`
|
||||
|
||||
|
||||
8) Pairing heuristics (v3):
|
||||
- Semi-hard course preference: tries preferred course first (A/B) and only falls back if preferred course has no seats.
|
||||
- Hole bottleneck mitigation: distributes HIGH/BEGINNER across start holes.
|
||||
- Tune via config/pxg.php -> pairing.*
|
||||
|
||||
|
||||
9) Admin auth (Sanctum):
|
||||
- Register middleware alias in `app/Http/Kernel.php`:
|
||||
'role' => \App\Http\Middleware\EnsureAdminRole::class
|
||||
|
||||
- Install Sanctum if not present: `composer require laravel/sanctum` then `php artisan sanctum:install`
|
||||
- Ensure `api` middleware includes `EnsureFrontendRequestsAreStateful` only if you need cookie auth; this project uses bearer tokens.
|
||||
- Seed admin user: `php artisan db:seed --class=AdminUserSeeder`
|
||||
|
||||
|
||||
10) Exports (Excel friendly CSV):
|
||||
- Start sheet: GET /api/v1/admin/events/{event}/exports/start-sheet.csv
|
||||
- Pairing list: GET /api/v1/admin/events/{event}/exports/pairing-list.csv
|
||||
|
||||
11) Flight ops:
|
||||
- Lock/unlock flights for sponsor/VIP so pairing engine won't use them.
|
||||
- Manual assign/move/remove members via admin endpoints.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Add to app/Http/Kernel.php $routeMiddleware:
|
||||
'role' => \App\Http\Middleware\EnsureAdminRole::class,
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
# TOURNAMENT PXG 2026 — Laravel API Skeleton (matches Vue frontend contract)
|
||||
|
||||
This is a **Laravel API skeleton** you can copy into an existing Laravel 10/11 project.
|
||||
It matches the frontend contract used by the Vue project:
|
||||
|
||||
## Endpoints (v1)
|
||||
- `GET /api/v1/events/{event}`
|
||||
- `POST /api/v1/events/{event}/registrations`
|
||||
- `POST /api/v1/events/{event}/groups`
|
||||
- `GET /api/v1/groups/{code}`
|
||||
- `POST /api/v1/groups/{code}/join`
|
||||
- `POST /api/v1/registrations/{registration}/pay`
|
||||
- `POST /api/v1/pairing/lookup`
|
||||
- `POST /api/v1/pairing/otp/request`
|
||||
- `POST /api/v1/pairing/otp/verify`
|
||||
- `GET /api/v1/pairing/me` (Bearer pairing_token)
|
||||
- `POST /api/v1/webhooks/xendit`
|
||||
|
||||
## Environment variables (.env)
|
||||
Add:
|
||||
- `XENDIT_API_KEY=...`
|
||||
- `XENDIT_WEBHOOK_TOKEN=...` (the token you set in Xendit dashboard)
|
||||
- `WA_OTP_DRIVER=log` (default) or your provider driver name
|
||||
- `PAIRING_TOKEN_TTL_MINUTES=30`
|
||||
- `OTP_TTL_MINUTES=5`
|
||||
|
||||
## WhatsApp OTP
|
||||
This skeleton provides an interface `OtpSenderInterface` + default driver `LogOtpSender` which writes OTP to logs.
|
||||
Replace it with your WhatsApp Business API provider integration.
|
||||
|
||||
## Xendit
|
||||
This skeleton includes a minimal `XenditService` stub.
|
||||
Replace `createInvoice()` with real Xendit Invoice API call and map the webhook payload accordingly.
|
||||
|
||||
## Installation approach
|
||||
1. Create a fresh Laravel project (or use existing).
|
||||
2. Copy the `app/`, `routes/`, and `database/migrations/` from this skeleton into your project.
|
||||
3. Run migrations:
|
||||
```bash
|
||||
php artisan migrate
|
||||
```
|
||||
4. Seed flights:
|
||||
```bash
|
||||
php artisan pxg:seed-flights --event=1
|
||||
```
|
||||
5. Configure `.env` and run:
|
||||
```bash
|
||||
php artisan serve
|
||||
```
|
||||
|
||||
## Notes
|
||||
- Pairing token is an **encrypted bearer token** (not Sanctum), issued after OTP verification.
|
||||
- OTP uses hashing + rate-limits (basic) + attempt limits.
|
||||
- Pairing assignment logic is **NOT implemented** here (you can plug your pairing job/service later).
|
||||
The API returns pairing info only if a registration has been assigned to a flight via `flight_members`.
|
||||
|
||||
|
||||
## Admin Dashboard (API)
|
||||
- Login: `POST /api/v1/admin/login` with email+password -> returns Sanctum token
|
||||
- Default seeded admin:
|
||||
- email: `admin@pxg.local`
|
||||
- password: `pxg2026admin`
|
||||
Run:
|
||||
```bash
|
||||
php artisan db:seed --class=AdminUserSeeder
|
||||
```
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Jobs\AssignPairingJob;
|
||||
use App\Models\Event;
|
||||
use App\Models\Registration;
|
||||
|
||||
class PairingTick extends Command
|
||||
{
|
||||
protected $signature = 'pxg:pairing-tick {--event=}';
|
||||
protected $description = 'Scan events for confirmed registrations without flights and dispatch pairing jobs.';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$eventOpt = $this->option('event');
|
||||
|
||||
$events = Event::query();
|
||||
if ($eventOpt) {
|
||||
$events->where('id', (int)$eventOpt);
|
||||
} else {
|
||||
// default: only events that are active/open (best effort)
|
||||
$events->where(function($q){
|
||||
$q->whereNull('registration_close_at')
|
||||
->orWhere('registration_close_at', '>=', now()->subDays(1));
|
||||
});
|
||||
}
|
||||
|
||||
$ids = $events->pluck('id')->all();
|
||||
$dispatched = 0;
|
||||
|
||||
foreach ($ids as $eventId) {
|
||||
$pending = Registration::where('event_id', $eventId)
|
||||
->where('status', 'CONFIRMED')
|
||||
->whereDoesntHave('flightMember')
|
||||
->count();
|
||||
|
||||
if ($pending > 0) {
|
||||
dispatch(new AssignPairingJob((int)$eventId));
|
||||
$dispatched++;
|
||||
$this->info("Dispatched pairing job for event {$eventId} (pending {$pending})");
|
||||
}
|
||||
}
|
||||
|
||||
if ($dispatched === 0) {
|
||||
$this->line('No events require pairing.');
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Services\PairingEngine;
|
||||
|
||||
class RunPairing extends Command
|
||||
{
|
||||
protected $signature = 'pxg:pair {--event=1}';
|
||||
protected $description = 'Run pairing engine for confirmed registrations (assign to flights).';
|
||||
|
||||
public function handle(PairingEngine $engine): int
|
||||
{
|
||||
$eventId = (int) $this->option('event');
|
||||
$res = $engine->run($eventId);
|
||||
$this->info('Assigned: '.$res['assigned']);
|
||||
foreach (($res['notes'] ?? []) as $n) {
|
||||
$this->line('- '.$n);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Event;
|
||||
use App\Models\Flight;
|
||||
|
||||
class SeedFlights extends Command
|
||||
{
|
||||
protected $signature = 'pxg:seed-flights {--event=1}';
|
||||
protected $description = 'Seed 72 flights for 2 courses (A/B) with 36 start points each (18 holes x 2 tees).';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$eventId = (int) $this->option('event');
|
||||
$event = Event::find($eventId);
|
||||
if (!$event) {
|
||||
$this->error('Event not found: '.$eventId);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create A01..A36 and B01..B36
|
||||
$this->info('Seeding flights for event '.$eventId);
|
||||
|
||||
$courses = ['A','B'];
|
||||
foreach ($courses as $course) {
|
||||
$idx = 1;
|
||||
for ($hole=1; $hole<=18; $hole++) {
|
||||
foreach (['A','B'] as $tee) {
|
||||
$code = $course . str_pad((string)$idx, 2, '0', STR_PAD_LEFT);
|
||||
Flight::updateOrCreate(
|
||||
['event_id' => $eventId, 'code' => $code],
|
||||
[
|
||||
'course' => $course,
|
||||
'start_hole' => $hole,
|
||||
'start_tee' => $tee,
|
||||
'type' => 'NORMAL',
|
||||
'status' => 'OPEN',
|
||||
]
|
||||
);
|
||||
$idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->info('Done.');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
// Run pairing dispatcher every minute
|
||||
$schedule->command('pxg:pairing-tick')->everyMinute();
|
||||
}
|
||||
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* The list of the inputs that are never flashed to the session on validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AuditLog;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AuditController extends Controller
|
||||
{
|
||||
public function index(Event $event, Request $request)
|
||||
{
|
||||
$q = AuditLog::where('event_id',$event->id);
|
||||
if ($request->filled('action')) $q->where('action', $request->string('action'));
|
||||
$rows = $q->orderByDesc('id')->limit(500)->get()->map(function($a){
|
||||
return [
|
||||
'id' => $a->id,
|
||||
'action' => $a->action,
|
||||
'entity_type' => $a->entity_type,
|
||||
'entity_id' => $a->entity_id,
|
||||
'actor_user_id' => $a->actor_user_id,
|
||||
'meta' => $a->meta,
|
||||
'created_at' => $a->created_at->toIso8601String(),
|
||||
];
|
||||
});
|
||||
return response()->json(['data'=>$rows]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Models\User;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function login(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'email' => ['required','email'],
|
||||
'password' => ['required','string'],
|
||||
]);
|
||||
|
||||
$user = User::where('email', $data['email'])->first();
|
||||
if (!$user || !Hash::check($data['password'], $user->password)) {
|
||||
return response()->json(['message' => 'Invalid credentials'], 401);
|
||||
}
|
||||
|
||||
$token = $user->createToken('pxg-admin')->plainTextToken;
|
||||
|
||||
return response()->json([
|
||||
'token' => $token,
|
||||
'user' => [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'email' => $user->email,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function logout(Request $request)
|
||||
{
|
||||
$request->user()->currentAccessToken()->delete();
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Checkin;
|
||||
use App\Models\Event;
|
||||
use App\Models\Flight;
|
||||
use App\Models\Registration;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BatchPrintController extends Controller
|
||||
{
|
||||
public function badges(Event $event, Request $request)
|
||||
{
|
||||
$ids = $request->query('ids');
|
||||
$checkedIn = $request->boolean('checked_in');
|
||||
|
||||
$q = Registration::where('event_id',$event->id)->with(['player','flightMember.flight']);
|
||||
|
||||
if ($checkedIn) {
|
||||
$regIds = Checkin::where('event_id',$event->id)->whereNotNull('checked_in_at')->pluck('registration_id')->all();
|
||||
$q->whereIn('id', $regIds);
|
||||
} elseif ($ids) {
|
||||
$idArr = array_filter(array_map('intval', explode(',', (string)$ids)));
|
||||
$q->whereIn('id', $idArr);
|
||||
} else {
|
||||
return response('Missing ids or checked_in=1', 422);
|
||||
}
|
||||
|
||||
$regs = $q->orderBy('id')->get();
|
||||
return response($this->badgesHtml($event->name, $regs))->header('Content-Type','text/html');
|
||||
}
|
||||
|
||||
public function scorecards(Event $event, Request $request)
|
||||
{
|
||||
$course = strtoupper((string)$request->query('course',''));
|
||||
$q = Flight::where('event_id',$event->id)->with(['members.registration.player'])->orderBy('course')->orderBy('code');
|
||||
if (in_array($course, ['A','B'], true)) $q->where('course',$course);
|
||||
$flights = $q->get();
|
||||
return response($this->scorecardsHtml($event->name, $flights))->header('Content-Type','text/html');
|
||||
}
|
||||
|
||||
private function badgesHtml(string $eventName, $regs): string
|
||||
{
|
||||
$eventName = e($eventName);
|
||||
$cards = '';
|
||||
foreach ($regs as $r) {
|
||||
$name = e($r->player?->name ?? '');
|
||||
$code = e($r->registration_code);
|
||||
$flight = $r->flightMember?->flight;
|
||||
$flightText = $flight ? "Flight {$flight->code} • Course {$flight->course} • Hole {$flight->start_hole}{$flight->start_tee}" : "Flight: —";
|
||||
$flightText = e($flightText);
|
||||
|
||||
$cards .= "<div class='badge'>
|
||||
<div class='h'>
|
||||
<div class='logo'>PXG</div>
|
||||
<div style='text-align:right'>
|
||||
<div class='title'>{$eventName}</div>
|
||||
<div class='sub'>Badge</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='name'>{$name}</div>
|
||||
<div class='code'>{$code}</div>
|
||||
<div class='meta'>{$flightText}</div>
|
||||
</div>";
|
||||
}
|
||||
|
||||
return "<!doctype html><html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||
<style>
|
||||
body{font-family:ui-sans-serif,system-ui; margin:0; background:#fff;}
|
||||
.page{width:min(1100px, 96vw); margin: 14px auto;}
|
||||
.grid{display:grid; grid-template-columns: repeat(3, 1fr); gap: 10px;}
|
||||
.badge{border:2px solid #111; border-radius:16px; padding:12px; page-break-inside:avoid;}
|
||||
.h{display:flex; justify-content:space-between; align-items:center;}
|
||||
.logo{width:46px;height:46px;border-radius:14px;background:#111;color:#fff;display:grid;place-items:center;font-weight:900;}
|
||||
.title{font-weight:900; font-size:12px;}
|
||||
.sub{font-size:11px;color:#444;}
|
||||
.name{font-weight:1000; font-size:18px; margin-top:10px; line-height:1.1;}
|
||||
.code{font-family:ui-monospace; font-weight:900; margin-top:6px;}
|
||||
.meta{color:#444; font-size:11px; margin-top:8px; line-height:1.3;}
|
||||
@media print { .page{width:100%;} .grid{grid-template-columns: repeat(3, 1fr);} }
|
||||
</style></head><body onload='window.print()'>
|
||||
<div class='page'><div class='grid'>{$cards}</div></div>
|
||||
</body></html>";
|
||||
}
|
||||
|
||||
private function scorecardsHtml(string $eventName, $flights): string
|
||||
{
|
||||
$eventName = e($eventName);
|
||||
$cards = '';
|
||||
|
||||
foreach ($flights as $f) {
|
||||
$flightCode = e($f->code);
|
||||
$course = e($f->course);
|
||||
$hole = e((string)$f->start_hole);
|
||||
$tee = e($f->start_tee);
|
||||
|
||||
$rows = '';
|
||||
foreach ($f->members->sortBy('seat_no') as $m) {
|
||||
$seat = (int)$m->seat_no;
|
||||
$name = e($m->registration?->player?->name ?? '');
|
||||
$band = e((string)($m->registration?->handicap_band ?? '—'));
|
||||
$hcp = e((string)($m->registration?->handicap_value ?? '—'));
|
||||
$rows .= "<tr><td>{$seat}</td><td>{$name}</td><td>{$band}</td><td>{$hcp}</td></tr>";
|
||||
}
|
||||
|
||||
$cards .= "<div class='card'>
|
||||
<div class='h'>
|
||||
<div>
|
||||
<div class='h1'>{$eventName}</div>
|
||||
<div class='meta'>Scorecard • Flight {$flightCode}</div>
|
||||
</div>
|
||||
<div class='meta'>Course {$course} • Start Hole {$hole}{$tee}</div>
|
||||
</div>
|
||||
<table>
|
||||
<thead><tr><th>Seat</th><th>Player</th><th>Band</th><th>HCP</th></tr></thead>
|
||||
<tbody>{$rows}</tbody>
|
||||
</table>
|
||||
<div class='meta' style='margin-top:10px;'>Scoring: Stableford Nett • Shotgun Start</div>
|
||||
</div>";
|
||||
}
|
||||
|
||||
return "<!doctype html><html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||
<style>
|
||||
body{font-family:ui-sans-serif,system-ui; margin:0; background:#fff;}
|
||||
.page{width:min(1100px, 96vw); margin: 14px auto;}
|
||||
.grid{display:grid; grid-template-columns: 1fr; gap: 12px;}
|
||||
.card{border:2px solid #111; border-radius:16px; padding:14px; page-break-inside:avoid;}
|
||||
.h{display:flex; justify-content:space-between; align-items:flex-end; gap:10px;}
|
||||
.h1{font-weight:1000; font-size:16px;}
|
||||
.meta{color:#444; font-size:12px;}
|
||||
table{width:100%; border-collapse:collapse; margin-top:10px;}
|
||||
th,td{border-bottom:1px solid #e5e5e5; padding:9px 8px; text-align:left;}
|
||||
th{font-size:11px; color:#444; text-transform:uppercase; letter-spacing:.4px;}
|
||||
@media print { .page{width:100%;} }
|
||||
</style></head><body onload='window.print()'>
|
||||
<div class='page'><div class='grid'>{$cards}</div></div>
|
||||
</body></html>";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Checkin;
|
||||
use App\Models\Event;
|
||||
use App\Models\Registration;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CheckinController extends Controller
|
||||
{
|
||||
public function lookup(Event $event, Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'code' => ['required','string','max:40'],
|
||||
]);
|
||||
|
||||
$reg = Registration::where('event_id',$event->id)
|
||||
->where('registration_code', $data['code'])
|
||||
->with(['player','flightMember.flight'])
|
||||
->first();
|
||||
|
||||
if (!$reg) return response()->json(['message' => 'Registration not found'], 404);
|
||||
|
||||
$checkin = Checkin::where('event_id',$event->id)->where('registration_id',$reg->id)->first();
|
||||
|
||||
return response()->json([
|
||||
'registration' => [
|
||||
'id' => $reg->id,
|
||||
'registration_code' => $reg->registration_code,
|
||||
'status' => $reg->status,
|
||||
'player' => [
|
||||
'name' => $reg->player?->name,
|
||||
'phone' => $reg->player?->phone,
|
||||
'email' => $reg->player?->email,
|
||||
],
|
||||
'flight' => $reg->flightMember?->flight ? [
|
||||
'code' => $reg->flightMember->flight->code,
|
||||
'course' => $reg->flightMember->flight->course,
|
||||
'start_hole' => (int)$reg->flightMember->flight->start_hole,
|
||||
'start_tee' => $reg->flightMember->flight->start_tee,
|
||||
] : null
|
||||
],
|
||||
'checkin' => $checkin ? [
|
||||
'checked_in_at' => optional($checkin->checked_in_at)->toIso8601String(),
|
||||
'method' => $checkin->method,
|
||||
] : null
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkin(Event $event, Request $request, AuditLogger $audit)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'registration_id' => ['required','integer','exists:registrations,id'],
|
||||
'method' => ['nullable','in:manual,qr'],
|
||||
]);
|
||||
|
||||
$reg = Registration::where('event_id',$event->id)->findOrFail((int)$data['registration_id']);
|
||||
|
||||
$checkin = Checkin::updateOrCreate(
|
||||
['event_id' => $event->id, 'registration_id' => $reg->id],
|
||||
[
|
||||
'checked_in_at' => now(),
|
||||
'checked_in_by' => $request->user()?->id,
|
||||
'method' => $data['method'] ?? 'manual',
|
||||
]
|
||||
);
|
||||
|
||||
$audit->log($event->id, $request->user()?->id, 'checkin', 'registration', $reg->id, [
|
||||
'registration_code' => $reg->registration_code,
|
||||
'method' => $checkin->method
|
||||
]);
|
||||
|
||||
return response()->json(['ok' => true, 'checked_in_at' => $checkin->checked_in_at->toIso8601String()]);
|
||||
}
|
||||
|
||||
public function undo(Event $event, Request $request, AuditLogger $audit)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'registration_id' => ['required','integer','exists:registrations,id'],
|
||||
]);
|
||||
|
||||
$reg = Registration::where('event_id',$event->id)->findOrFail((int)$data['registration_id']);
|
||||
$checkin = Checkin::where('event_id',$event->id)->where('registration_id',$reg->id)->first();
|
||||
if ($checkin) $checkin->delete();
|
||||
|
||||
$audit->log($event->id, $request->user()?->id, 'checkin_undo', 'registration', $reg->id, [
|
||||
'registration_code' => $reg->registration_code
|
||||
]);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function bulkImport(Event $event, Request $request, AuditLogger $audit)
|
||||
{
|
||||
$request->validate([
|
||||
'file' => ['required','file','mimes:csv,txt','max:5120'],
|
||||
'method' => ['nullable','in:manual,qr'],
|
||||
]);
|
||||
|
||||
$content = file_get_contents($request->file('file')->getRealPath());
|
||||
$lines = preg_split("/\r\n|\n|\r/", trim($content));
|
||||
if (count($lines) < 1) return response()->json(['message'=>'Empty file'], 422);
|
||||
|
||||
$first = trim($lines[0]);
|
||||
$hasHeader = str_contains(strtolower($first), 'registration_code') || str_contains(strtolower($first), 'code');
|
||||
if ($hasHeader) array_shift($lines);
|
||||
|
||||
$method = $request->input('method','manual');
|
||||
$ok = 0; $skipped = 0; $errors = [];
|
||||
|
||||
foreach ($lines as $i => $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '') continue;
|
||||
$cols = str_getcsv($line);
|
||||
$code = trim($cols[0] ?? '');
|
||||
if ($code === '') { $skipped++; continue; }
|
||||
|
||||
$reg = \App\Models\Registration::where('event_id',$event->id)->where('registration_code',$code)->first();
|
||||
if (!$reg) { $errors[] = ['row' => ($hasHeader? $i+2 : $i+1), 'message' => "not found: {$code}"]; $skipped++; continue; }
|
||||
|
||||
\App\Models\Checkin::updateOrCreate(
|
||||
['event_id' => $event->id, 'registration_id' => $reg->id],
|
||||
['checked_in_at' => now(), 'checked_in_by' => $request->user()?->id, 'method' => $method]
|
||||
);
|
||||
|
||||
$audit->log($event->id, $request->user()?->id, 'checkin_bulk', 'registration', $reg->id, [
|
||||
'registration_code' => $reg->registration_code,
|
||||
'method' => $method
|
||||
]);
|
||||
|
||||
$ok++;
|
||||
}
|
||||
|
||||
return response()->json(['ok'=>true,'checked_in'=>$ok,'skipped'=>$skipped,'errors'=>$errors]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Event;
|
||||
use App\Models\Flight;
|
||||
use App\Models\Registration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function show(Event $event)
|
||||
{
|
||||
$registered = Registration::where('event_id', $event->id)->count();
|
||||
$confirmed = Registration::where('event_id', $event->id)->where('status','CONFIRMED')->count();
|
||||
$pendingPairing = Registration::where('event_id', $event->id)->where('status','CONFIRMED')->whereDoesntHave('flightMember')->count();
|
||||
$flightsFull = Flight::where('event_id', $event->id)->where('status','FULL')->count();
|
||||
|
||||
$courseLoadRows = DB::table('flight_members')
|
||||
->join('flights','flight_members.flight_id','=','flights.id')
|
||||
->where('flights.event_id',$event->id)
|
||||
->select('flights.course', DB::raw('count(*) as cnt'))
|
||||
->groupBy('flights.course')
|
||||
->get();
|
||||
|
||||
$courseLoad = ['A'=>0,'B'=>0];
|
||||
foreach ($courseLoadRows as $r) $courseLoad[$r->course] = (int)$r->cnt;
|
||||
|
||||
return response()->json([
|
||||
'event' => [
|
||||
'id' => $event->id,
|
||||
'name' => $event->name,
|
||||
],
|
||||
'kpi' => [
|
||||
'registered' => $registered,
|
||||
'confirmed' => $confirmed,
|
||||
'pending_pairing' => $pendingPairing,
|
||||
'flights_full' => $flightsFull,
|
||||
],
|
||||
'course_load' => $courseLoad,
|
||||
]);
|
||||
}
|
||||
|
||||
public function exportStartSheet(Event $event): StreamedResponse
|
||||
{
|
||||
$filename = "start-sheet-event-{$event->id}.csv";
|
||||
|
||||
$flights = Flight::where('event_id', $event->id)
|
||||
->orderBy('course')->orderBy('code')
|
||||
->get();
|
||||
|
||||
$callback = function() use ($flights) {
|
||||
$out = fopen('php://output', 'w');
|
||||
fputcsv($out, ['Course','Flight','Start Hole','Tee','Type','Status','Member Count']);
|
||||
foreach ($flights as $f) {
|
||||
$cnt = DB::table('flight_members')->where('flight_id',$f->id)->count();
|
||||
fputcsv($out, [$f->course,$f->code,$f->start_hole,$f->start_tee,$f->type,$f->status,$cnt]);
|
||||
}
|
||||
fclose($out);
|
||||
};
|
||||
|
||||
return response()->streamDownload($callback, $filename, ['Content-Type' => 'text/csv']);
|
||||
}
|
||||
|
||||
public function exportPairingList(Event $event): StreamedResponse
|
||||
{
|
||||
$filename = "pairing-list-event-{$event->id}.csv";
|
||||
|
||||
$rows = Registration::where('event_id', $event->id)
|
||||
->with(['player','flightMember.flight'])
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
$callback = function() use ($rows) {
|
||||
$out = fopen('php://output', 'w');
|
||||
fputcsv($out, ['Reg ID','Reg Code','Name','Phone','Email','Status','Band','HCP','Pairing Mode','Course Pref','Flight','Course Assigned','Start Hole','Tee']);
|
||||
foreach ($rows as $r) {
|
||||
$f = $r->flightMember?->flight;
|
||||
fputcsv($out, [
|
||||
$r->id,
|
||||
$r->registration_code,
|
||||
$r->player?->name,
|
||||
$r->player?->phone,
|
||||
$r->player?->email,
|
||||
$r->status,
|
||||
$r->handicap_band,
|
||||
$r->handicap_value,
|
||||
$r->pairing_mode,
|
||||
$r->course_pref,
|
||||
$f?->code,
|
||||
$f?->course,
|
||||
$f?->start_hole,
|
||||
$f?->start_tee,
|
||||
]);
|
||||
}
|
||||
fclose($out);
|
||||
};
|
||||
|
||||
return response()->streamDownload($callback, $filename, ['Content-Type' => 'text/csv']);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\AssignPairingJob;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EventAdminController extends Controller
|
||||
{
|
||||
public function finalize(Event $event)
|
||||
{
|
||||
$event->pairing_finalized_at = now();
|
||||
$event->save();
|
||||
return response()->json(['ok' => true, 'pairing_finalized_at' => $event->pairing_finalized_at->toIso8601String()]);
|
||||
}
|
||||
|
||||
public function publish(Event $event)
|
||||
{
|
||||
if (!$event->pairing_finalized_at) {
|
||||
return response()->json(['message' => 'Finalize pairing first'], 409);
|
||||
}
|
||||
$event->pairing_published_at = now();
|
||||
$event->save();
|
||||
return response()->json(['ok' => true, 'pairing_published_at' => $event->pairing_published_at->toIso8601String()]);
|
||||
}
|
||||
|
||||
public function unfinalize(Event $event)
|
||||
{
|
||||
$event->pairing_finalized_at = null;
|
||||
$event->pairing_published_at = null;
|
||||
$event->save();
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Event;
|
||||
use App\Models\Flight;
|
||||
use App\Models\FlightMember;
|
||||
use App\Models\Registration;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class FlightsController extends Controller
|
||||
{
|
||||
public function index(Event $event)
|
||||
{
|
||||
$rows = Flight::where('event_id', $event->id)
|
||||
->orderBy('course')->orderBy('code')
|
||||
->get()
|
||||
->map(function($f){
|
||||
$cnt = DB::table('flight_members')->where('flight_id', $f->id)->count();
|
||||
return [
|
||||
'id' => $f->id,
|
||||
'course' => $f->course,
|
||||
'code' => $f->code,
|
||||
'start_hole' => (int)$f->start_hole,
|
||||
'start_tee' => $f->start_tee,
|
||||
'type' => $f->type,
|
||||
'status' => $f->status,
|
||||
'member_count' => (int)$cnt,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
|
||||
public function show(Flight $flight)
|
||||
{
|
||||
$flight->load(['members.registration.player']);
|
||||
$members = $flight->members->map(function($m){
|
||||
return [
|
||||
'flight_member_id' => $m->id,
|
||||
'seat_no' => (int)$m->seat_no,
|
||||
'registration_id' => $m->registration_id,
|
||||
'registration_code' => $m->registration?->registration_code,
|
||||
'name' => $m->registration?->player?->name,
|
||||
'band' => $m->registration?->handicap_band,
|
||||
'hcp' => $m->registration?->handicap_value,
|
||||
];
|
||||
})->sortBy('seat_no')->values();
|
||||
|
||||
return response()->json([
|
||||
'flight' => [
|
||||
'id' => $flight->id,
|
||||
'event_id' => $flight->event_id,
|
||||
'course' => $flight->course,
|
||||
'code' => $flight->code,
|
||||
'start_hole' => (int)$flight->start_hole,
|
||||
'start_tee' => $flight->start_tee,
|
||||
'type' => $flight->type,
|
||||
'status' => $flight->status,
|
||||
],
|
||||
'members' => $members,
|
||||
]);
|
||||
}
|
||||
|
||||
public function assign(Flight $flight, Request $request, AuditLogger $audit)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'registration_id' => ['nullable','integer','exists:registrations,id'],
|
||||
'registration_code' => ['nullable','string','max:40'],
|
||||
'seat_no' => ['required','integer','in:1,2,3,4'],
|
||||
]);
|
||||
|
||||
$reg = null;
|
||||
if (!empty($data['registration_id'])) {
|
||||
$reg = Registration::findOrFail((int)$data['registration_id']);
|
||||
} else if (!empty($data['registration_code'])) {
|
||||
$reg = Registration::where('registration_code', $data['registration_code'])->firstOrFail();
|
||||
} else {
|
||||
return response()->json(['message' => 'registration_id or registration_code required'], 422);
|
||||
}
|
||||
|
||||
if ($reg->event_id !== $flight->event_id) {
|
||||
return response()->json(['message' => 'Registration not in this event'], 422);
|
||||
}
|
||||
|
||||
if (FlightMember::where('registration_id', $reg->id)->exists()) {
|
||||
return response()->json(['message' => 'Registration already assigned to a flight'], 409);
|
||||
}
|
||||
|
||||
if (FlightMember::where('flight_id', $flight->id)->where('seat_no', (int)$data['seat_no'])->exists()) {
|
||||
return response()->json(['message' => 'Seat already taken'], 409);
|
||||
}
|
||||
|
||||
FlightMember::create([
|
||||
'flight_id' => $flight->id,
|
||||
'registration_id' => $reg->id,
|
||||
'seat_no' => (int)$data['seat_no'],
|
||||
'lock_flag' => false,
|
||||
]);
|
||||
|
||||
$this->refreshFlightStatus($flight->id);
|
||||
|
||||
$audit->log($flight->event_id, $request->user()?->id, 'flight_member_assign', 'flight', $flight->id, [
|
||||
'registration_id' => $reg->id,
|
||||
'registration_code' => $reg->registration_code,
|
||||
'seat_no' => (int)$data['seat_no'],
|
||||
]);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function moveMember(FlightMember $flightMember, Request $request, AuditLogger $audit)
|
||||
{
|
||||
$event = Event::find($flightMember->flight->event_id);
|
||||
if ($event && $event->pairing_finalized_at) {
|
||||
return response()->json(['message' => 'Pairing finalized. Use swap request workflow.'], 409);
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'to_flight_id' => ['required','integer','exists:flights,id'],
|
||||
'to_seat_no' => ['required','integer','in:1,2,3,4'],
|
||||
]);
|
||||
|
||||
$toFlight = Flight::findOrFail((int)$data['to_flight_id']);
|
||||
|
||||
if ($toFlight->event_id !== $flightMember->flight->event_id) {
|
||||
return response()->json(['message' => 'Target flight is not in same event'], 422);
|
||||
}
|
||||
|
||||
if (FlightMember::where('flight_id', $toFlight->id)->where('seat_no', (int)$data['to_seat_no'])->exists()) {
|
||||
return response()->json(['message' => 'Target seat already taken'], 409);
|
||||
}
|
||||
|
||||
$fromFlightId = $flightMember->flight_id;
|
||||
|
||||
DB::transaction(function() use ($flightMember, $toFlight, $data){
|
||||
$flightMember->flight_id = $toFlight->id;
|
||||
$flightMember->seat_no = (int)$data['to_seat_no'];
|
||||
$flightMember->save();
|
||||
});
|
||||
|
||||
$this->refreshFlightStatus($fromFlightId);
|
||||
$this->refreshFlightStatus($toFlight->id);
|
||||
|
||||
$audit->log($toFlight->event_id, $request->user()?->id, 'flight_member_move', 'flight_member', $flightMember->id, [
|
||||
'from_flight_id' => $fromFlightId,
|
||||
'to_flight_id' => $toFlight->id,
|
||||
'to_seat_no' => (int)$data['to_seat_no'],
|
||||
]);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function removeMember(FlightMember $flightMember, Request $request, AuditLogger $audit)
|
||||
{
|
||||
$event = Event::find($flightMember->flight->event_id);
|
||||
if ($event && $event->pairing_finalized_at) {
|
||||
return response()->json(['message' => 'Pairing finalized. Use swap request workflow.'], 409);
|
||||
}
|
||||
|
||||
$flightId = $flightMember->flight_id;
|
||||
$regId = $flightMember->registration_id;
|
||||
|
||||
$flightMember->delete();
|
||||
$this->refreshFlightStatus($flightId);
|
||||
|
||||
$audit->log(Flight::find($flightId)?->event_id, $request->user()?->id, 'flight_member_remove', 'flight', $flightId, [
|
||||
'registration_id' => $regId,
|
||||
]);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function lock(Flight $flight, Request $request, AuditLogger $audit)
|
||||
{
|
||||
$flight->type = 'SPONSOR_LOCKED';
|
||||
$flight->status = 'LOCKED';
|
||||
$flight->save();
|
||||
|
||||
$audit->log($flight->event_id, $request->user()?->id, 'flight_lock', 'flight', $flight->id);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function unlock(Flight $flight, Request $request, AuditLogger $audit)
|
||||
{
|
||||
$flight->type = 'NORMAL';
|
||||
$cnt = DB::table('flight_members')->where('flight_id', $flight->id)->count();
|
||||
$flight->status = $cnt >= 4 ? 'FULL' : 'OPEN';
|
||||
$flight->save();
|
||||
|
||||
$audit->log($flight->event_id, $request->user()?->id, 'flight_unlock', 'flight', $flight->id);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
private function refreshFlightStatus(int $flightId): void
|
||||
{
|
||||
$count = DB::table('flight_members')->where('flight_id', $flightId)->count();
|
||||
Flight::where('id', $flightId)->update(['status' => $count >= 4 ? 'FULL' : 'OPEN']);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Event;
|
||||
use App\Models\Player;
|
||||
use App\Models\Registration;
|
||||
use App\Services\RegistrationCodeService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ImportController extends Controller
|
||||
{
|
||||
/**
|
||||
* CSV columns (header required):
|
||||
* name, phone, email, handicap_type(HI|EVENT_BAND), handicap_value(optional), handicap_band(LOW|MID|HIGH|BEGINNER),
|
||||
* pairing_mode(LEVEL|BALANCED|RANDOM), course_pref(A|B|ANY), status(optional: PENDING_PAYMENT|CONFIRMED|WAITLIST)
|
||||
*/
|
||||
public function importRegistrations(Event $event, Request $request, RegistrationCodeService $codeService)
|
||||
{
|
||||
$request->validate([
|
||||
'file' => ['required','file','mimes:csv,txt','max:5120'],
|
||||
]);
|
||||
|
||||
$content = file_get_contents($request->file('file')->getRealPath());
|
||||
$lines = preg_split("/\r\n|\n|\r/", trim($content));
|
||||
if (count($lines) < 2) return response()->json(['message' => 'CSV must include header + at least 1 row'], 422);
|
||||
|
||||
$header = str_getcsv(array_shift($lines));
|
||||
$header = array_map(fn($h)=> strtolower(trim($h)), $header);
|
||||
|
||||
$required = ['name','phone','email','handicap_type','handicap_band','pairing_mode','course_pref'];
|
||||
foreach ($required as $r) {
|
||||
if (!in_array($r, $header, true)) {
|
||||
return response()->json(['message' => "Missing required column: {$r}"], 422);
|
||||
}
|
||||
}
|
||||
|
||||
$idx = array_flip($header);
|
||||
|
||||
$created = 0;
|
||||
$skipped = 0;
|
||||
$errors = [];
|
||||
|
||||
DB::transaction(function() use ($lines, $idx, $event, $codeService, &$created, &$skipped, &$errors){
|
||||
foreach ($lines as $i => $line) {
|
||||
if (trim($line) === '') continue;
|
||||
$row = str_getcsv($line);
|
||||
|
||||
$get = function($key) use ($row, $idx){
|
||||
return isset($idx[$key]) ? trim((string)($row[$idx[$key]] ?? '')) : '';
|
||||
};
|
||||
|
||||
$name = $get('name');
|
||||
$phone = $get('phone');
|
||||
$email = $get('email');
|
||||
|
||||
if ($name==='' || $phone==='' || $email==='') {
|
||||
$errors[] = ['row' => $i+2, 'message' => 'name/phone/email required'];
|
||||
$skipped++; continue;
|
||||
}
|
||||
|
||||
// avoid duplicate by email+event (simple)
|
||||
$exists = Registration::where('event_id',$event->id)->whereHas('player', fn($q)=> $q->where('email',$email))->exists();
|
||||
if ($exists) { $skipped++; continue; }
|
||||
|
||||
$handicapType = strtoupper($get('handicap_type'));
|
||||
$handicapBand = strtoupper($get('handicap_band'));
|
||||
$pairingMode = strtoupper($get('pairing_mode'));
|
||||
$coursePref = strtoupper($get('course_pref'));
|
||||
$status = strtoupper($get('status') ?: 'PENDING_PAYMENT');
|
||||
$hcpValRaw = $get('handicap_value');
|
||||
$hcpVal = $hcpValRaw !== '' ? (float)$hcpValRaw : null;
|
||||
|
||||
$valid = in_array($handicapType, ['HI','EVENT_BAND'], true)
|
||||
&& in_array($handicapBand, ['LOW','MID','HIGH','BEGINNER'], true)
|
||||
&& in_array($pairingMode, ['LEVEL','BALANCED','RANDOM'], true)
|
||||
&& in_array($coursePref, ['A','B','ANY'], true)
|
||||
&& in_array($status, ['DRAFT','PENDING_PAYMENT','CONFIRMED','WAITLIST','CANCELLED'], true);
|
||||
|
||||
if (!$valid) {
|
||||
$errors[] = ['row' => $i+2, 'message' => 'invalid enum value(s)'];
|
||||
$skipped++; continue;
|
||||
}
|
||||
|
||||
$player = Player::create([
|
||||
'name' => $name,
|
||||
'phone' => $phone,
|
||||
'email' => $email,
|
||||
]);
|
||||
|
||||
Registration::create([
|
||||
'event_id' => $event->id,
|
||||
'player_id' => $player->id,
|
||||
'type' => 'INDIVIDUAL',
|
||||
'status' => $status,
|
||||
'handicap_type' => $handicapType,
|
||||
'handicap_value' => $hcpVal,
|
||||
'handicap_band' => $handicapBand,
|
||||
'pairing_mode' => $pairingMode,
|
||||
'course_pref' => $coursePref,
|
||||
'registration_code' => $codeService->make(),
|
||||
]);
|
||||
|
||||
$created++;
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'created' => $created,
|
||||
'skipped' => $skipped,
|
||||
'errors' => $errors,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\AssignPairingJob;
|
||||
use App\Models\Event;
|
||||
|
||||
class PairingAdminController extends Controller
|
||||
{
|
||||
public function run(Event $event)
|
||||
{
|
||||
if ($event->pairing_finalized_at) {
|
||||
return response()->json(['message' => 'Pairing is finalized. Unfinalize to run again.'], 409);
|
||||
}
|
||||
dispatch(new AssignPairingJob((int)$event->id));
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Event;
|
||||
use App\Models\PaymentIntent;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PaymentsController extends Controller
|
||||
{
|
||||
public function index(Event $event, Request $request)
|
||||
{
|
||||
$q = PaymentIntent::query()
|
||||
->whereHas('registration', fn($qq)=> $qq->where('event_id',$event->id));
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$q->where('status', $request->string('status'));
|
||||
}
|
||||
|
||||
if ($request->filled('q')) {
|
||||
$term = trim((string)$request->string('q'));
|
||||
$q->where(function($qq) use ($term){
|
||||
$qq->where('provider_ref_id','like',"%{$term}%")
|
||||
->orWhere('registration_id', $term);
|
||||
});
|
||||
}
|
||||
|
||||
$rows = $q->orderByDesc('id')->limit(1000)->get()->map(function($p){
|
||||
return [
|
||||
'id' => $p->id,
|
||||
'registration_id' => $p->registration_id,
|
||||
'provider_ref_id' => $p->provider_ref_id,
|
||||
'amount' => (int) $p->amount,
|
||||
'status' => $p->status,
|
||||
'paid_at' => optional($p->paid_at)->toIso8601String(),
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Event;
|
||||
use App\Models\Flight;
|
||||
use App\Models\Registration;
|
||||
|
||||
class PrintController extends Controller
|
||||
{
|
||||
public function badge(Event $event, Registration $registration)
|
||||
{
|
||||
if ($registration->event_id !== $event->id) abort(404);
|
||||
|
||||
$registration->load(['player','flightMember.flight']);
|
||||
|
||||
$name = e($registration->player?->name ?? '');
|
||||
$code = e($registration->registration_code);
|
||||
$flight = $registration->flightMember?->flight;
|
||||
$flightText = $flight ? "Flight {$flight->code} • Course {$flight->course} • Hole {$flight->start_hole}{$flight->start_tee}" : "Flight: —";
|
||||
|
||||
return response($this->badgeHtml($event->name, $name, $code, $flightText))
|
||||
->header('Content-Type','text/html');
|
||||
}
|
||||
|
||||
public function scorecard(Event $event, Flight $flight)
|
||||
{
|
||||
if ($flight->event_id !== $event->id) abort(404);
|
||||
$flight->load(['members.registration.player']);
|
||||
|
||||
$members = $flight->members->sortBy('seat_no')->map(function($m){
|
||||
return [
|
||||
'seat' => (int)$m->seat_no,
|
||||
'name' => e($m->registration?->player?->name ?? ''),
|
||||
'hcp' => e((string)($m->registration?->handicap_value ?? '—')),
|
||||
'band' => e((string)($m->registration?->handicap_band ?? '—')),
|
||||
];
|
||||
})->values()->all();
|
||||
|
||||
return response($this->scorecardHtml($event->name, $flight, $members))
|
||||
->header('Content-Type','text/html');
|
||||
}
|
||||
|
||||
private function badgeHtml(string $eventName, string $name, string $code, string $flightText): string
|
||||
{
|
||||
$eventName = e($eventName);
|
||||
return "<!doctype html><html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||
<style>
|
||||
body{font-family:ui-sans-serif,system-ui; margin:0; background:#fff;}
|
||||
.badge{width: 340px; border:2px solid #111; border-radius:16px; padding:14px; margin: 12px auto;}
|
||||
.h{display:flex; justify-content:space-between; align-items:center;}
|
||||
.logo{width:54px;height:54px;border-radius:16px;background:#111;color:#fff;display:grid;place-items:center;font-weight:900;}
|
||||
.title{font-weight:900; font-size:14px;}
|
||||
.name{font-weight:1000; font-size:22px; margin-top:10px;}
|
||||
.code{font-family:ui-monospace; font-weight:900; margin-top:6px;}
|
||||
.meta{color:#444; font-size:12px; margin-top:8px; line-height:1.3;}
|
||||
@media print { .badge{page-break-inside:avoid;} }
|
||||
</style></head><body onload='window.print()'>
|
||||
<div class='badge'>
|
||||
<div class='h'>
|
||||
<div class='logo'>PXG</div>
|
||||
<div style='text-align:right'>
|
||||
<div class='title'>{$eventName}</div>
|
||||
<div style='font-size:12px;color:#444'>Badge</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='name'>{$name}</div>
|
||||
<div class='code'>${code}</div>
|
||||
<div class='meta'>{$flightText}</div>
|
||||
</div>
|
||||
</body></html>";
|
||||
}
|
||||
|
||||
private function scorecardHtml(string $eventName, Flight $flight, array $members): string
|
||||
{
|
||||
$eventName = e($eventName);
|
||||
$flightCode = e($flight->code);
|
||||
$course = e($flight->course);
|
||||
$hole = e((string)$flight->start_hole);
|
||||
$tee = e($flight->start_tee);
|
||||
|
||||
$rows = '';
|
||||
foreach ($members as $m) {
|
||||
$rows .= "<tr><td>{$m['seat']}</td><td>{$m['name']}</td><td>{$m['band']}</td><td>{$m['hcp']}</td></tr>";
|
||||
}
|
||||
|
||||
return "<!doctype html><html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||
<style>
|
||||
body{font-family:ui-sans-serif,system-ui; margin:0; background:#fff;}
|
||||
.wrap{width:min(900px, 92vw); margin: 14px auto;}
|
||||
.card{border:2px solid #111; border-radius:16px; padding:14px;}
|
||||
.h{display:flex; justify-content:space-between; align-items:flex-end; gap:10px;}
|
||||
.h1{font-weight:1000; font-size:18px;}
|
||||
.meta{color:#444; font-size:12px;}
|
||||
table{width:100%; border-collapse:collapse; margin-top:12px;}
|
||||
th,td{border-bottom:1px solid #e5e5e5; padding:10px 8px; text-align:left;}
|
||||
th{font-size:12px; color:#444; text-transform:uppercase; letter-spacing:.4px;}
|
||||
@media print { .card{page-break-inside:avoid;} }
|
||||
</style></head><body onload='window.print()'>
|
||||
<div class='wrap'>
|
||||
<div class='card'>
|
||||
<div class='h'>
|
||||
<div>
|
||||
<div class='h1'>{$eventName}</div>
|
||||
<div class='meta'>Scorecard • Flight {$flightCode}</div>
|
||||
</div>
|
||||
<div class='meta'>Course {$course} • Start Hole {$hole}{$tee}</div>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead><tr><th>Seat</th><th>Player</th><th>Band</th><th>HCP</th></tr></thead>
|
||||
<tbody>{$rows}</tbody>
|
||||
</table>
|
||||
|
||||
<div class='meta' style='margin-top:12px;'>Scoring: Stableford Nett • Shotgun Start</div>
|
||||
</div>
|
||||
</div>
|
||||
</body></html>";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Event;
|
||||
use App\Models\Registration;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RegistrationsController extends Controller
|
||||
{
|
||||
public function index(Event $event, Request $request)
|
||||
{
|
||||
$q = Registration::where('event_id', $event->id)
|
||||
->with(['player','flightMember.flight']);
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$q->where('status', $request->string('status'));
|
||||
}
|
||||
if ($request->filled('course_pref')) {
|
||||
$q->where('course_pref', $request->string('course_pref'));
|
||||
}
|
||||
if ($request->filled('q')) {
|
||||
$term = trim((string)$request->string('q'));
|
||||
$q->where(function($qq) use ($term){
|
||||
$qq->where('registration_code','like',"%{$term}%")
|
||||
->orWhereHas('player', function($p) use ($term){
|
||||
$p->where('name','like',"%{$term}%")
|
||||
->orWhere('phone','like',"%{$term}%")
|
||||
->orWhere('email','like',"%{$term}%");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$rows = $q->orderByDesc('id')->limit(1000)->get()->map(function($r){
|
||||
return [
|
||||
'id' => $r->id,
|
||||
'registration_code' => $r->registration_code,
|
||||
'player_name' => $r->player?->name,
|
||||
'player_phone' => $r->player?->phone,
|
||||
'player_email' => $r->player?->email,
|
||||
'status' => $r->status,
|
||||
'handicap_band' => $r->handicap_band,
|
||||
'handicap_value' => $r->handicap_value,
|
||||
'pairing_mode' => $r->pairing_mode,
|
||||
'course_pref' => $r->course_pref,
|
||||
'flight_code' => $r->flightMember?->flight?->code,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
|
||||
public function show(Registration $registration)
|
||||
{
|
||||
$registration->load(['player','flightMember.flight.members.registration.player']);
|
||||
|
||||
$flight = $registration->flightMember?->flight;
|
||||
|
||||
$members = [];
|
||||
if ($flight) {
|
||||
foreach ($flight->members as $m) {
|
||||
$members[] = [
|
||||
'flight_member_id' => $m->id,
|
||||
'seat_no' => (int)$m->seat_no,
|
||||
'registration_id' => $m->registration_id,
|
||||
'name' => $m->registration?->player?->name,
|
||||
'phone' => $m->registration?->player?->phone,
|
||||
'email' => $m->registration?->player?->email,
|
||||
'band' => $m->registration?->handicap_band,
|
||||
'hcp' => $m->registration?->handicap_value,
|
||||
'is_you' => $m->registration_id === $registration->id,
|
||||
];
|
||||
}
|
||||
usort($members, fn($a,$b)=> $a['seat_no'] <=> $b['seat_no']);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'registration' => [
|
||||
'id' => $registration->id,
|
||||
'registration_code' => $registration->registration_code,
|
||||
'status' => $registration->status,
|
||||
'pairing_mode' => $registration->pairing_mode,
|
||||
'course_pref' => $registration->course_pref,
|
||||
'handicap_band' => $registration->handicap_band,
|
||||
'handicap_value' => $registration->handicap_value,
|
||||
],
|
||||
'player' => [
|
||||
'id' => $registration->player?->id,
|
||||
'name' => $registration->player?->name,
|
||||
'phone' => $registration->player?->phone,
|
||||
'email' => $registration->player?->email,
|
||||
'club' => $registration->player?->club,
|
||||
'shirt_size' => $registration->player?->shirt_size,
|
||||
],
|
||||
'flight' => $flight ? [
|
||||
'id' => $flight->id,
|
||||
'code' => $flight->code,
|
||||
'course' => $flight->course,
|
||||
'start_hole' => (int)$flight->start_hole,
|
||||
'start_tee' => $flight->start_tee,
|
||||
'type' => $flight->type,
|
||||
'status' => $flight->status,
|
||||
] : null,
|
||||
'members' => $members,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Registration $registration, Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'status' => ['required','in:DRAFT,PENDING_PAYMENT,CONFIRMED,WAITLIST,CANCELLED'],
|
||||
]);
|
||||
|
||||
$registration->status = $data['status'];
|
||||
$registration->save();
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Event;
|
||||
use App\Models\Flight;
|
||||
use App\Models\FlightMember;
|
||||
use App\Models\SwapRequest;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SwapRequestController extends Controller
|
||||
{
|
||||
public function index(Event $event, Request $request)
|
||||
{
|
||||
$q = SwapRequest::where('event_id',$event->id)->with(['flightMember.flight','flightMember.registration.player','toFlight']);
|
||||
if ($request->filled('status')) $q->where('status', strtoupper((string)$request->string('status')));
|
||||
$rows = $q->orderByDesc('id')->limit(500)->get()->map(function($s){
|
||||
return [
|
||||
'id' => $s->id,
|
||||
'status' => $s->status,
|
||||
'reason' => $s->reason,
|
||||
'requested_by' => $s->requested_by,
|
||||
'approved_by' => $s->approved_by,
|
||||
'approved_at' => optional($s->approved_at)->toIso8601String(),
|
||||
'from' => [
|
||||
'flight_code' => $s->flightMember?->flight?->code,
|
||||
'seat_no' => (int)($s->flightMember?->seat_no),
|
||||
'reg_code' => $s->flightMember?->registration?->registration_code,
|
||||
'name' => $s->flightMember?->registration?->player?->name,
|
||||
],
|
||||
'to' => [
|
||||
'flight_code' => $s->toFlight?->code,
|
||||
'seat_no' => (int)$s->to_seat_no,
|
||||
],
|
||||
'created_at' => $s->created_at->toIso8601String(),
|
||||
];
|
||||
});
|
||||
return response()->json(['data'=>$rows]);
|
||||
}
|
||||
|
||||
public function request(Event $event, Request $request, AuditLogger $audit)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'flight_member_id' => ['required','integer','exists:flight_members,id'],
|
||||
'to_flight_id' => ['required','integer','exists:flights,id'],
|
||||
'to_seat_no' => ['required','integer','in:1,2,3,4'],
|
||||
'reason' => ['nullable','string','max:250'],
|
||||
]);
|
||||
|
||||
$fm = FlightMember::with('flight')->findOrFail((int)$data['flight_member_id']);
|
||||
$toFlight = Flight::findOrFail((int)$data['to_flight_id']);
|
||||
|
||||
if ($fm->flight->event_id !== $event->id || $toFlight->event_id !== $event->id) {
|
||||
return response()->json(['message'=>'Event mismatch'], 422);
|
||||
}
|
||||
|
||||
$sr = SwapRequest::create([
|
||||
'event_id' => $event->id,
|
||||
'flight_member_id' => $fm->id,
|
||||
'to_flight_id' => $toFlight->id,
|
||||
'to_seat_no' => (int)$data['to_seat_no'],
|
||||
'reason' => $data['reason'] ?? null,
|
||||
'status' => 'PENDING',
|
||||
'requested_by' => $request->user()?->id,
|
||||
]);
|
||||
|
||||
$audit->log($event->id, $request->user()?->id, 'swap_requested', 'swap_request', $sr->id, [
|
||||
'from_flight' => $fm->flight->code,
|
||||
'from_seat' => $fm->seat_no,
|
||||
'to_flight' => $toFlight->code,
|
||||
'to_seat' => (int)$data['to_seat_no'],
|
||||
]);
|
||||
|
||||
return response()->json(['ok'=>true,'id'=>$sr->id]);
|
||||
}
|
||||
|
||||
public function approve(Event $event, SwapRequest $swapRequest, Request $request, AuditLogger $audit)
|
||||
{
|
||||
if ($swapRequest->event_id !== $event->id) return response()->json(['message'=>'Event mismatch'], 422);
|
||||
if ($swapRequest->status !== 'PENDING') return response()->json(['message'=>'Not pending'], 409);
|
||||
|
||||
$swapRequest->status = 'APPROVED';
|
||||
$swapRequest->approved_by = $request->user()?->id;
|
||||
$swapRequest->approved_at = now();
|
||||
$swapRequest->save();
|
||||
|
||||
$audit->log($event->id, $request->user()?->id, 'swap_approved', 'swap_request', $swapRequest->id);
|
||||
|
||||
return response()->json(['ok'=>true]);
|
||||
}
|
||||
|
||||
public function reject(Event $event, SwapRequest $swapRequest, Request $request, AuditLogger $audit)
|
||||
{
|
||||
if ($swapRequest->event_id !== $event->id) return response()->json(['message'=>'Event mismatch'], 422);
|
||||
if ($swapRequest->status !== 'PENDING') return response()->json(['message'=>'Not pending'], 409);
|
||||
|
||||
$swapRequest->status = 'REJECTED';
|
||||
$swapRequest->approved_by = $request->user()?->id;
|
||||
$swapRequest->approved_at = now();
|
||||
$swapRequest->save();
|
||||
|
||||
$audit->log($event->id, $request->user()?->id, 'swap_rejected', 'swap_request', $swapRequest->id);
|
||||
|
||||
return response()->json(['ok'=>true]);
|
||||
}
|
||||
|
||||
public function apply(Event $event, SwapRequest $swapRequest, Request $request, AuditLogger $audit)
|
||||
{
|
||||
if ($swapRequest->event_id !== $event->id) return response()->json(['message'=>'Event mismatch'], 422);
|
||||
if ($swapRequest->status !== 'APPROVED') return response()->json(['message'=>'Approve first'], 409);
|
||||
|
||||
$fm = FlightMember::with('flight')->findOrFail($swapRequest->flight_member_id);
|
||||
$toFlight = Flight::findOrFail($swapRequest->to_flight_id);
|
||||
|
||||
// Seat availability check
|
||||
$taken = FlightMember::where('flight_id',$toFlight->id)->where('seat_no',$swapRequest->to_seat_no)->exists();
|
||||
if ($taken) return response()->json(['message'=>'Target seat taken'], 409);
|
||||
|
||||
DB::transaction(function() use ($fm, $toFlight, $swapRequest){
|
||||
$fm->flight_id = $toFlight->id;
|
||||
$fm->seat_no = (int)$swapRequest->to_seat_no;
|
||||
$fm->save();
|
||||
$swapRequest->status = 'APPLIED';
|
||||
$swapRequest->save();
|
||||
});
|
||||
|
||||
$audit->log($event->id, $request->user()?->id, 'swap_applied', 'swap_request', $swapRequest->id);
|
||||
|
||||
return response()->json(['ok'=>true]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Event;
|
||||
|
||||
class EventController extends Controller
|
||||
{
|
||||
public function show(Event $event)
|
||||
{
|
||||
// Minimal payload; extend as needed.
|
||||
return response()->json([
|
||||
'id' => $event->id,
|
||||
'name' => $event->name,
|
||||
'date' => optional($event->date)->toDateString(),
|
||||
'venue' => $event->venue,
|
||||
'shotgun_mode' => (bool) $event->shotgun_mode,
|
||||
'courses' => $event->courses_json,
|
||||
'registration_open_at' => optional($event->registration_open_at)->toIso8601String(),
|
||||
'registration_close_at' => optional($event->registration_close_at)->toIso8601String(),
|
||||
'pairing_finalized_at' => optional($event->pairing_finalized_at)->toIso8601String(),
|
||||
'pairing_published_at' => optional($event->pairing_published_at)->toIso8601String(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\CreateGroupRequest;
|
||||
use App\Http\Requests\JoinGroupRequest;
|
||||
use App\Models\Event;
|
||||
use App\Models\Group;
|
||||
use App\Models\Player;
|
||||
use App\Models\Registration;
|
||||
use App\Services\GroupCodeService;
|
||||
use App\Services\RegistrationCodeService;
|
||||
|
||||
class GroupController extends Controller
|
||||
{
|
||||
public function store(Event $event, CreateGroupRequest $request, GroupCodeService $groupCodeService)
|
||||
{
|
||||
$data = $request->validated();
|
||||
|
||||
$group = Group::create([
|
||||
'event_id' => $event->id,
|
||||
'group_code' => $groupCodeService->make(),
|
||||
'size_target' => $data['size_target'],
|
||||
'group_name' => $data['group_name'] ?? null,
|
||||
'leader_player_id' => null,
|
||||
'status' => 'OPEN',
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'id' => $group->id,
|
||||
'group_code' => $group->group_code,
|
||||
'size_target' => $group->size_target,
|
||||
'status' => $group->status,
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function show(string $code)
|
||||
{
|
||||
$group = Group::where('group_code', $code)->firstOrFail();
|
||||
|
||||
$membersCount = Registration::where('group_id', $group->id)->count();
|
||||
|
||||
return response()->json([
|
||||
'id' => $group->id,
|
||||
'group_code' => $group->group_code,
|
||||
'size_target' => $group->size_target,
|
||||
'status' => $group->status,
|
||||
'members_count' => $membersCount,
|
||||
'group_name' => $group->group_name,
|
||||
]);
|
||||
}
|
||||
|
||||
public function join(string $code, JoinGroupRequest $request, RegistrationCodeService $regCodeService)
|
||||
{
|
||||
$group = Group::where('group_code', $code)->firstOrFail();
|
||||
$data = $request->validated();
|
||||
|
||||
// Simple "full" guard
|
||||
$membersCount = Registration::where('group_id', $group->id)->count();
|
||||
if ($membersCount >= $group->size_target) {
|
||||
return response()->json(['message' => 'Group is full'], 409);
|
||||
}
|
||||
|
||||
$player = Player::create([
|
||||
'name' => $data['player']['name'],
|
||||
'phone' => $data['player']['phone'],
|
||||
'email' => $data['player']['email'],
|
||||
]);
|
||||
|
||||
$registration = Registration::create([
|
||||
'event_id' => $group->event_id,
|
||||
'player_id' => $player->id,
|
||||
'type' => $membersCount === 0 ? 'GROUP_LEADER' : 'GROUP_MEMBER',
|
||||
'group_id' => $group->id,
|
||||
'status' => 'PENDING_PAYMENT',
|
||||
'handicap_type' => $data['handicap']['type'],
|
||||
'handicap_value' => $data['handicap']['value'] ?? null,
|
||||
'handicap_band' => $data['handicap']['band'],
|
||||
// Use balanced as default for group members; can be changed later in v2
|
||||
'pairing_mode' => 'BALANCED',
|
||||
'course_pref' => 'ANY',
|
||||
'registration_code' => $regCodeService->make(),
|
||||
]);
|
||||
|
||||
if ($membersCount === 0) {
|
||||
$group->leader_player_id = $player->id;
|
||||
$group->save();
|
||||
}
|
||||
|
||||
// Update group status
|
||||
$membersCount2 = $membersCount + 1;
|
||||
if ($membersCount2 >= $group->size_target) {
|
||||
$group->status = 'FULL';
|
||||
$group->save();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'id' => $registration->id,
|
||||
'registration_code' => $registration->registration_code,
|
||||
], 201);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\PairingLookupRequest;
|
||||
use App\Http\Requests\PairingOtpRequest;
|
||||
use App\Http\Requests\PairingOtpVerifyRequest;
|
||||
use App\Models\Registration;
|
||||
use App\Services\OtpService;
|
||||
use App\Services\PairingTokenService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PairingController extends Controller
|
||||
{
|
||||
public function lookup(PairingLookupRequest $request)
|
||||
{
|
||||
$code = $request->validated()['registration_code'];
|
||||
|
||||
$registration = Registration::where('registration_code', $code)->with('player')->firstOrFail();
|
||||
|
||||
// Mask phone for UI: +62***1234
|
||||
$phone = $registration->player->phone;
|
||||
$masked = $this->maskPhone($phone);
|
||||
|
||||
return response()->json([
|
||||
'registration_id' => $registration->id,
|
||||
'masked_phone' => $masked,
|
||||
]);
|
||||
}
|
||||
|
||||
public function requestOtp(PairingOtpRequest $request, OtpService $otpService)
|
||||
{
|
||||
$registrationId = $request->validated()['registration_id'];
|
||||
$registration = Registration::with('player')->findOrFail($registrationId);
|
||||
|
||||
$otpService->sendPairingOtp($registration);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function verifyOtp(PairingOtpVerifyRequest $request, OtpService $otpService, PairingTokenService $tokenService)
|
||||
{
|
||||
$data = $request->validated();
|
||||
$registration = Registration::with('player')->findOrFail($data['registration_id']);
|
||||
|
||||
$otpService->verifyPairingOtp($registration, $data['otp']);
|
||||
|
||||
$token = $tokenService->issue($registration->id);
|
||||
|
||||
return response()->json([
|
||||
'pairing_token' => $token,
|
||||
]);
|
||||
}
|
||||
|
||||
public function me(Request $request, PairingTokenService $tokenService)
|
||||
{
|
||||
$auth = $request->header('Authorization', '');
|
||||
if (!str_starts_with($auth, 'Bearer ')) {
|
||||
return response()->json(['message' => 'Unauthorized'], 401);
|
||||
}
|
||||
$token = trim(substr($auth, 7));
|
||||
|
||||
$registrationId = $tokenService->verify($token);
|
||||
if (!$registrationId) {
|
||||
return response()->json(['message' => 'Unauthorized'], 401);
|
||||
}
|
||||
|
||||
$registration = Registration::with('player', 'flightMember.flight.members.registration.player')
|
||||
->findOrFail($registrationId);
|
||||
|
||||
$flightMember = $registration->flightMember;
|
||||
$flight = $flightMember?->flight;
|
||||
|
||||
// Build members array for diagram (seat 1..4)
|
||||
$members = [];
|
||||
if ($flight) {
|
||||
foreach ($flight->members as $m) {
|
||||
$members[] = [
|
||||
'seat' => (int) $m->seat_no,
|
||||
'name' => $m->registration?->player?->name,
|
||||
'band' => $m->registration?->handicap_band,
|
||||
'hcp' => $m->registration?->handicap_value,
|
||||
'is_you' => $m->registration_id === $registration->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'registration' => [
|
||||
'status' => $registration->status,
|
||||
'player' => [
|
||||
'name' => $registration->player->name,
|
||||
'band' => $registration->handicap_band,
|
||||
'handicap' => $registration->handicap_value,
|
||||
],
|
||||
// Optional for UI copy; can be expanded later:
|
||||
'preferences' => [
|
||||
'pairing_mode' => $registration->pairing_mode,
|
||||
'pairing_mode_label' => strtolower($registration->pairing_mode) === 'LEVEL' ? 'level' : (strtolower($registration->pairing_mode) === 'RANDOM' ? 'random' : 'balanced'),
|
||||
],
|
||||
],
|
||||
'flight' => $flight ? [
|
||||
'code' => $flight->code,
|
||||
'course' => $flight->course,
|
||||
'start_hole' => (int) $flight->start_hole,
|
||||
'start_tee' => $flight->start_tee,
|
||||
'is_final' => $flight->status === 'FINAL',
|
||||
] : null,
|
||||
'members' => $members,
|
||||
]);
|
||||
}
|
||||
|
||||
private function maskPhone(string $phone): string
|
||||
{
|
||||
// crude masking; adjust as needed for E164 normalization
|
||||
$digits = preg_replace('/\D+/', '', $phone);
|
||||
if (strlen($digits) <= 4) return '+**' . $digits;
|
||||
$last4 = substr($digits, -4);
|
||||
return '+'.substr($digits, 0, 2) . '***' . $last4;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\PayRegistrationRequest;
|
||||
use App\Models\PaymentIntent;
|
||||
use App\Models\Registration;
|
||||
use App\Services\XenditService;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
public function pay(Registration $registration, PayRegistrationRequest $request, XenditService $xendit)
|
||||
{
|
||||
$data = $request->validated();
|
||||
|
||||
// TODO: determine amount from event pricing table
|
||||
$amount = 1000000; // placeholder IDR
|
||||
|
||||
$intent = PaymentIntent::create([
|
||||
'registration_id' => $registration->id,
|
||||
'provider' => 'XENDIT',
|
||||
'channel' => $data['method'], // INVOICE
|
||||
'amount' => $amount,
|
||||
'currency' => 'IDR',
|
||||
'status' => 'PENDING',
|
||||
]);
|
||||
|
||||
$invoice = $xendit->createInvoice($intent, $registration);
|
||||
|
||||
$intent->provider_ref_id = $invoice['provider_ref_id'];
|
||||
$intent->checkout_url = $invoice['checkout_url'];
|
||||
$intent->raw_payload = $invoice['raw_payload'] ?? null;
|
||||
$intent->save();
|
||||
|
||||
return response()->json([
|
||||
'payment_intent_id' => $intent->id,
|
||||
'checkout_url' => $intent->checkout_url,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StoreRegistrationRequest;
|
||||
use App\Models\Event;
|
||||
use App\Models\Player;
|
||||
use App\Models\Registration;
|
||||
use App\Services\RegistrationCodeService;
|
||||
|
||||
class RegistrationController extends Controller
|
||||
{
|
||||
public function store(Event $event, StoreRegistrationRequest $request, RegistrationCodeService $codeService)
|
||||
{
|
||||
$data = $request->validated();
|
||||
|
||||
$player = Player::create([
|
||||
'name' => $data['player']['name'],
|
||||
'phone' => $data['player']['phone'],
|
||||
'email' => $data['player']['email'],
|
||||
'club' => $data['player']['club'] ?? null,
|
||||
'shirt_size' => $data['player']['shirt_size'] ?? null,
|
||||
]);
|
||||
|
||||
$registration = Registration::create([
|
||||
'event_id' => $event->id,
|
||||
'player_id' => $player->id,
|
||||
'type' => 'INDIVIDUAL',
|
||||
'status' => 'PENDING_PAYMENT',
|
||||
'handicap_type' => $data['handicap']['type'],
|
||||
'handicap_value' => $data['handicap']['value'] ?? null,
|
||||
'handicap_band' => $data['handicap']['band'],
|
||||
'pairing_mode' => $data['preferences']['pairing_mode'],
|
||||
'course_pref' => $data['preferences']['course_pref'],
|
||||
'registration_code' => $codeService->make(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'id' => $registration->id,
|
||||
'registration_code' => $registration->registration_code,
|
||||
], 201);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\PaymentIntent;
|
||||
use App\Models\Registration;
|
||||
use App\Services\XenditService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class WebhookController extends Controller
|
||||
{
|
||||
public function xendit(Request $request, XenditService $xendit)
|
||||
{
|
||||
if (!$xendit->verifyWebhook($request)) {
|
||||
return response()->json(['message' => 'Invalid webhook signature'], 401);
|
||||
}
|
||||
|
||||
$payload = $request->all();
|
||||
|
||||
// NOTE: Map this based on the actual Xendit product you use.
|
||||
// For Invoice webhook, you typically get invoice id + status.
|
||||
$providerRefId = $payload['id'] ?? $payload['data']['id'] ?? null;
|
||||
$status = strtoupper($payload['status'] ?? $payload['data']['status'] ?? '');
|
||||
|
||||
if (!$providerRefId) {
|
||||
return response()->json(['message' => 'Missing provider_ref_id'], 422);
|
||||
}
|
||||
|
||||
$intent = PaymentIntent::where('provider_ref_id', $providerRefId)->first();
|
||||
if (!$intent) {
|
||||
// idempotent: ignore unknown references
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
// Convert Xendit statuses to our statuses
|
||||
$mapped = match ($status) {
|
||||
'PAID', 'SETTLED' => 'PAID',
|
||||
'EXPIRED' => 'EXPIRED',
|
||||
'FAILED' => 'FAILED',
|
||||
'CANCELED', 'CANCELLED' => 'CANCELLED',
|
||||
default => 'PENDING',
|
||||
};
|
||||
|
||||
$intent->status = $mapped;
|
||||
$intent->raw_payload = $payload;
|
||||
if ($mapped === 'PAID') {
|
||||
$intent->paid_at = now();
|
||||
}
|
||||
$intent->save();
|
||||
|
||||
if ($mapped === 'PAID') {
|
||||
$reg = Registration::find($intent->registration_id);
|
||||
if ($reg && $reg->status !== 'CONFIRMED') {
|
||||
$reg->status = 'CONFIRMED';
|
||||
$reg->save();
|
||||
}
|
||||
dispatch(new \App\Jobs\AssignPairingJob((int)$reg->event_id));
|
||||
}
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, ValidatesRequests;
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array<int, class-string|string>
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array<string, array<int, class-string|string>>
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's middleware aliases.
|
||||
*
|
||||
* Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
|
||||
*
|
||||
* @var array<string, class-string|string>
|
||||
*/
|
||||
protected $middlewareAliases = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'precognitive' => \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
|
||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*/
|
||||
protected function redirectTo(Request $request): ?string
|
||||
{
|
||||
return $request->expectsJson() ? null : route('login');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EnsureAdminRole
|
||||
{
|
||||
public function handle(Request $request, Closure $next, ...$roles)
|
||||
{
|
||||
$user = $request->user();
|
||||
if (!$user) return response()->json(['message' => 'Unauthorized'], 401);
|
||||
|
||||
if (!empty($roles)) {
|
||||
$role = $user->role ?? 'committee';
|
||||
if (!in_array($role, $roles, true)) {
|
||||
return response()->json(['message' => 'Forbidden'], 403);
|
||||
}
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, string ...$guards): Response
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts(): array
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array<int, string>|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
|
||||
|
||||
class ValidateSignature extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the query string parameters that should be ignored.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
// 'fbclid',
|
||||
// 'utm_campaign',
|
||||
// 'utm_content',
|
||||
// 'utm_medium',
|
||||
// 'utm_source',
|
||||
// 'utm_term',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateGroupRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool { return true; }
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'size_target' => ['required','integer','in:2,3,4'],
|
||||
'group_name' => ['nullable','string','max:120'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class JoinGroupRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool { return true; }
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'player.name' => ['required','string','max:120'],
|
||||
'player.phone' => ['required','string','max:40'],
|
||||
'player.email' => ['required','email','max:180'],
|
||||
|
||||
'handicap.type' => ['required','in:HI,EVENT_BAND'],
|
||||
'handicap.value' => ['nullable','numeric','min:0','max:60'],
|
||||
'handicap.band' => ['required','in:LOW,MID,HIGH,BEGINNER'],
|
||||
|
||||
'consent' => ['required','boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PairingLookupRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool { return true; }
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'registration_code' => ['required','string','max:40'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PairingOtpRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool { return true; }
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'registration_id' => ['required','integer','exists:registrations,id'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PairingOtpVerifyRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool { return true; }
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'registration_id' => ['required','integer','exists:registrations,id'],
|
||||
'otp' => ['required','string','min:4','max:8'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PayRegistrationRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool { return true; }
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'method' => ['required','in:INVOICE'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreRegistrationRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool { return true; }
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'player.name' => ['required','string','max:120'],
|
||||
'player.phone' => ['required','string','max:40'],
|
||||
'player.email' => ['required','email','max:180'],
|
||||
'player.club' => ['nullable','string','max:120'],
|
||||
'player.shirt_size' => ['nullable','string','max:10'],
|
||||
|
||||
'handicap.type' => ['required','in:HI,EVENT_BAND'],
|
||||
'handicap.value' => ['nullable','numeric','min:0','max:60'],
|
||||
'handicap.band' => ['required','in:LOW,MID,HIGH,BEGINNER'],
|
||||
|
||||
'preferences.pairing_mode' => ['required','in:LEVEL,BALANCED,RANDOM'],
|
||||
'preferences.course_pref' => ['required','in:A,B,ANY'],
|
||||
|
||||
'consent' => ['required','boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Services\PairingEngine;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AssignPairingJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function __construct(public int $eventId) {}
|
||||
|
||||
public function handle(PairingEngine $engine): void
|
||||
{
|
||||
$result = $engine->run($this->eventId);
|
||||
Log::info('[PXG Pairing] assigned='.$result['assigned'], ['notes' => $result['notes'] ?? []]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AuditLog extends Model
|
||||
{
|
||||
protected $fillable = ['event_id','actor_user_id','action','entity_type','entity_id','meta'];
|
||||
|
||||
protected $casts = ['meta' => 'array'];
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Checkin extends Model
|
||||
{
|
||||
protected $fillable = ['event_id','registration_id','checked_in_at','checked_in_by','method'];
|
||||
|
||||
protected $casts = ['checked_in_at' => 'datetime'];
|
||||
|
||||
public function registration(){ return $this->belongsTo(Registration::class); }
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Event extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name','date','venue','shotgun_mode','courses_json',
|
||||
'registration_open_at','registration_close_at',
|
||||
'pairing_finalized_at','pairing_published_at'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'date' => 'date',
|
||||
'shotgun_mode' => 'boolean',
|
||||
'courses_json' => 'array',
|
||||
'registration_open_at' => 'datetime',
|
||||
'registration_close_at' => 'datetime',
|
||||
'pairing_finalized_at' => 'datetime',
|
||||
'pairing_published_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Flight extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'event_id','course','code','start_hole','start_tee','type','status'
|
||||
];
|
||||
|
||||
public function members(){
|
||||
return $this->hasMany(FlightMember::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FlightMember extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'flight_id','registration_id','seat_no','lock_flag'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'lock_flag' => 'boolean'
|
||||
];
|
||||
|
||||
public function flight(){
|
||||
return $this->belongsTo(Flight::class);
|
||||
}
|
||||
|
||||
public function registration(){
|
||||
return $this->belongsTo(Registration::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Group extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'event_id','group_code','size_target','leader_player_id','status','group_name'
|
||||
];
|
||||
|
||||
public function registrations(){
|
||||
return $this->hasMany(Registration::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OtpRequest extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'purpose','registration_id','phone_e164','otp_hash','expires_at',
|
||||
'attempts','status','request_ip','user_agent'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'expires_at' => 'datetime'
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PaymentIntent extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'registration_id','provider','channel','amount','currency',
|
||||
'status','provider_ref_id','checkout_url','paid_at','raw_payload'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'paid_at' => 'datetime',
|
||||
'raw_payload' => 'array'
|
||||
];
|
||||
|
||||
public function registration(){
|
||||
return $this->belongsTo(Registration::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Player extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name','phone','email','club','shirt_size','gender','notes'
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Registration extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'event_id','player_id','type','group_id','status',
|
||||
'handicap_type','handicap_value','handicap_band',
|
||||
'pairing_mode','course_pref','registration_code'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'handicap_value' => 'decimal:1'
|
||||
];
|
||||
|
||||
public function player(){
|
||||
return $this->belongsTo(Player::class);
|
||||
}
|
||||
|
||||
public function event(){
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
|
||||
public function group(){
|
||||
return $this->belongsTo(Group::class);
|
||||
}
|
||||
|
||||
public function flightMember(){
|
||||
return $this->hasOne(FlightMember::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SwapRequest extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'event_id','flight_member_id','to_flight_id','to_seat_no','reason',
|
||||
'status','requested_by','approved_by','approved_at'
|
||||
];
|
||||
|
||||
protected $casts = ['approved_at' => 'datetime'];
|
||||
|
||||
public function flightMember(){ return $this->belongsTo(FlightMember::class); }
|
||||
public function toFlight(){ return $this->belongsTo(Flight::class, 'to_flight_id'); }
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
// use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The model to policy mappings for the application.
|
||||
*
|
||||
* @var array<class-string, class-string>
|
||||
*/
|
||||
protected $policies = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event to listener mappings for the application.
|
||||
*
|
||||
* @var array<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if events and listeners should be automatically discovered.
|
||||
*/
|
||||
public function shouldDiscoverEvents(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class PxgServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
// Register pxg config
|
||||
$this->mergeConfigFrom(__DIR__.'/../../config/pxg.php', 'pxg');
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to your application's "home" route.
|
||||
*
|
||||
* Typically, users are redirected here after authentication.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/home';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, and other route configuration.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||
});
|
||||
|
||||
$this->routes(function () {
|
||||
Route::middleware('api')
|
||||
->prefix('api')
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\AuditLog;
|
||||
|
||||
class AuditLogger
|
||||
{
|
||||
public function log(?int $eventId, ?int $actorUserId, string $action, ?string $entityType=null, ?int $entityId=null, array $meta=[]): void
|
||||
{
|
||||
AuditLog::create([
|
||||
'event_id' => $eventId,
|
||||
'actor_user_id' => $actorUserId,
|
||||
'action' => $action,
|
||||
'entity_type' => $entityType,
|
||||
'entity_id' => $entityId,
|
||||
'meta' => $meta ?: null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class DevAutoConfirm
|
||||
{
|
||||
public function enabled(): bool
|
||||
{
|
||||
return (bool) env('PXG_DEV_AUTO_CONFIRM', false);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class GroupCodeService
|
||||
{
|
||||
public function make(): string
|
||||
{
|
||||
$alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
||||
$s = '';
|
||||
for ($i=0;$i<6;$i++){
|
||||
$s .= $alphabet[random_int(0, strlen($alphabet)-1)];
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\OtpSender;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LogOtpSender implements OtpSenderInterface
|
||||
{
|
||||
public function sendWhatsApp(string $phoneE164, string $message): void
|
||||
{
|
||||
Log::info('[PXG OTP][WA_LOG_DRIVER] '.$phoneE164.' :: '.$message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\OtpSender;
|
||||
|
||||
interface OtpSenderInterface
|
||||
{
|
||||
public function sendWhatsApp(string $phoneE164, string $message): void;
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\OtpRequest;
|
||||
use App\Models\Registration;
|
||||
use App\Services\OtpSender\LogOtpSender;
|
||||
use App\Services\OtpSender\OtpSenderInterface;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class OtpService
|
||||
{
|
||||
public function sender(): OtpSenderInterface
|
||||
{
|
||||
$driver = config('pxg.wa_otp_driver', 'log');
|
||||
// Add more drivers later (qontak, interakt, twilio, etc)
|
||||
return match ($driver) {
|
||||
'log' => new LogOtpSender(),
|
||||
default => new LogOtpSender(),
|
||||
};
|
||||
}
|
||||
|
||||
public function sendPairingOtp(Registration $registration): void
|
||||
{
|
||||
$ttl = config('pxg.otp_ttl_minutes', 5);
|
||||
$maxPer10m = config('pxg.otp_rate_limit_per_phone', 3);
|
||||
|
||||
$phone = $this->toE164($registration->player->phone);
|
||||
|
||||
// Basic rate-limit: count last 10 minutes
|
||||
$recentCount = OtpRequest::where('phone_e164', $phone)
|
||||
->where('created_at', '>=', now()->subMinutes(10))
|
||||
->count();
|
||||
|
||||
if ($recentCount >= $maxPer10m) {
|
||||
abort(429, 'Too many OTP requests. Please try again later.');
|
||||
}
|
||||
|
||||
$otp = (string) random_int(100000, 999999);
|
||||
|
||||
OtpRequest::create([
|
||||
'purpose' => 'PAIRING_VIEW',
|
||||
'registration_id' => $registration->id,
|
||||
'phone_e164' => $phone,
|
||||
'otp_hash' => Hash::make($otp),
|
||||
'expires_at' => now()->addMinutes($ttl),
|
||||
'attempts' => 0,
|
||||
'status' => 'SENT',
|
||||
'request_ip' => request()->ip(),
|
||||
'user_agent' => (string) request()->userAgent(),
|
||||
]);
|
||||
|
||||
$msg = "TOURNAMENT PXG 2026\nYour OTP: {$otp}\nValid for {$ttl} minutes.";
|
||||
$this->sender()->sendWhatsApp($phone, $msg);
|
||||
}
|
||||
|
||||
public function verifyPairingOtp(Registration $registration, string $otp): void
|
||||
{
|
||||
$maxAttempts = config('pxg.otp_max_attempts', 5);
|
||||
$phone = $this->toE164($registration->player->phone);
|
||||
|
||||
$req = OtpRequest::where('registration_id', $registration->id)
|
||||
->where('phone_e164', $phone)
|
||||
->whereIn('status', ['SENT'])
|
||||
->orderByDesc('id')
|
||||
->first();
|
||||
|
||||
if (!$req) abort(404, 'OTP not found. Please request OTP again.');
|
||||
if ($req->expires_at->isPast()) {
|
||||
$req->status = 'EXPIRED'; $req->save();
|
||||
abort(410, 'OTP expired. Please request OTP again.');
|
||||
}
|
||||
if ($req->attempts >= $maxAttempts) {
|
||||
$req->status = 'LOCKED'; $req->save();
|
||||
abort(423, 'Too many attempts. Please request OTP again later.');
|
||||
}
|
||||
|
||||
$req->attempts += 1;
|
||||
$req->save();
|
||||
|
||||
if (!Hash::check($otp, $req->otp_hash)) {
|
||||
abort(401, 'Invalid OTP.');
|
||||
}
|
||||
|
||||
$req->status = 'VERIFIED';
|
||||
$req->save();
|
||||
}
|
||||
|
||||
private function toE164(string $phone): string
|
||||
{
|
||||
// Basic normalization for Indonesia numbers: 08xx -> +628xx
|
||||
$p = preg_replace('/\D+/', '', $phone);
|
||||
if (Str::startsWith($p, '0')) {
|
||||
$p = '62'.substr($p, 1);
|
||||
}
|
||||
if (!Str::startsWith($p, '62')) {
|
||||
// fallback
|
||||
$p = '62'.$p;
|
||||
}
|
||||
return '+'.$p;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,484 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Flight;
|
||||
use App\Models\FlightMember;
|
||||
use App\Models\Group;
|
||||
use App\Models\Registration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PairingEngine
|
||||
{
|
||||
/**
|
||||
* Pairing Engine v3
|
||||
* - Course A/B balancing (soft) + semi-hard course_pref (try preferred first).
|
||||
* - Hole bottleneck mitigation for HIGH/BEGINNER: spread high-like players across start holes.
|
||||
* - LEVEL: keep homogeneous band flights when possible.
|
||||
* - BALANCED: target composition LOW, MID, MID, HIGH with pace guardrails.
|
||||
*/
|
||||
public function run(int $eventId): array
|
||||
{
|
||||
return DB::transaction(function () use ($eventId) {
|
||||
|
||||
$flights = Flight::where('event_id', $eventId)
|
||||
->where('type', 'NORMAL')
|
||||
->with(['members.registration'])
|
||||
->lockForUpdate()
|
||||
->get()
|
||||
->keyBy('id');
|
||||
|
||||
$seatOrder = config('pxg.pairing.seat_order', [1,2,3,4]);
|
||||
|
||||
// Seat availability map
|
||||
$flightSeats = [];
|
||||
foreach ($flights as $f) {
|
||||
$taken = $f->members->pluck('seat_no')->map(fn($x)=> (int)$x)->all();
|
||||
$available = array_values(array_diff($seatOrder, $taken));
|
||||
$flightSeats[$f->id] = $available;
|
||||
}
|
||||
|
||||
$assigned = 0;
|
||||
$notes = [];
|
||||
|
||||
$getPendingRegs = function () use ($eventId) {
|
||||
return Registration::where('event_id', $eventId)
|
||||
->where('status', 'CONFIRMED')
|
||||
->whereDoesntHave('flightMember')
|
||||
->with(['player','group'])
|
||||
->get();
|
||||
};
|
||||
|
||||
$regs = $getPendingRegs();
|
||||
if ($regs->isEmpty()) {
|
||||
return ['assigned' => 0, 'notes' => ['no pending confirmed registrations']];
|
||||
}
|
||||
|
||||
// Balancing stats
|
||||
$courseLoad = $this->computeCourseLoad($eventId);
|
||||
$holeHighLikeLoad = $this->computeHoleHighLikeLoad($eventId); // by start_hole (1..18)
|
||||
|
||||
// 1) Group-of-4 placement
|
||||
$groupIds = $regs->whereNotNull('group_id')->pluck('group_id')->unique()->values();
|
||||
if ($groupIds->isNotEmpty()) {
|
||||
$groups = Group::whereIn('id', $groupIds)->where('size_target', 4)->get();
|
||||
foreach ($groups as $g) {
|
||||
$groupRegs = Registration::where('group_id', $g->id)
|
||||
->where('status', 'CONFIRMED')
|
||||
->whereDoesntHave('flightMember')
|
||||
->with('player')
|
||||
->get();
|
||||
if ($groupRegs->count() !== 4) continue;
|
||||
|
||||
$coursePref = 'ANY';
|
||||
$leader = $groupRegs->firstWhere('type', 'GROUP_LEADER') ?? $groupRegs->first();
|
||||
if ($leader && in_array($leader->course_pref, ['A','B'])) $coursePref = $leader->course_pref;
|
||||
|
||||
$flightId = $this->findEmptyFlightBalanced($flights, $flightSeats, $courseLoad, $coursePref);
|
||||
if (!$flightId) { $notes[] = "no empty flight for group {$g->group_code}"; continue; }
|
||||
|
||||
$seats = $flightSeats[$flightId];
|
||||
if (count($seats) < 4) continue;
|
||||
|
||||
$i = 0;
|
||||
foreach ($groupRegs as $r) {
|
||||
FlightMember::create([
|
||||
'flight_id' => $flightId,
|
||||
'registration_id' => $r->id,
|
||||
'seat_no' => $seats[$i],
|
||||
'lock_flag' => false,
|
||||
]);
|
||||
$assigned++; $i++;
|
||||
$courseLoad[$flights[$flightId]->course] = ($courseLoad[$flights[$flightId]->course] ?? 0) + 1;
|
||||
if ($this->isHighLike($r->handicap_band)) {
|
||||
$h = (int)$flights[$flightId]->start_hole;
|
||||
$holeHighLikeLoad[$h] = ($holeHighLikeLoad[$h] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
$flightSeats[$flightId] = array_values(array_slice($seats, 4));
|
||||
$this->refreshFlightStatus($flightId);
|
||||
$notes[] = "group {$g->group_code} -> flight {$flights[$flightId]->code}";
|
||||
}
|
||||
}
|
||||
|
||||
// refresh remaining regs
|
||||
$regs = $getPendingRegs();
|
||||
|
||||
// 2) LEVEL by band (semi-hard course_pref)
|
||||
$levelRegs = $regs->where('pairing_mode', 'LEVEL')->values();
|
||||
foreach (['LOW','MID','HIGH','BEGINNER'] as $band) {
|
||||
foreach ($levelRegs->where('handicap_band', $band)->values() as $r) {
|
||||
$flightId = $this->findBestFlightForLevel($flights, $flightSeats, $courseLoad, $holeHighLikeLoad, $band, $r->course_pref);
|
||||
if (!$flightId) break;
|
||||
|
||||
$seat = array_shift($flightSeats[$flightId]);
|
||||
FlightMember::create([
|
||||
'flight_id' => $flightId,
|
||||
'registration_id' => $r->id,
|
||||
'seat_no' => $seat,
|
||||
'lock_flag' => false,
|
||||
]);
|
||||
$assigned++;
|
||||
$courseLoad[$flights[$flightId]->course] = ($courseLoad[$flights[$flightId]->course] ?? 0) + 1;
|
||||
if ($this->isHighLike($r->handicap_band)) {
|
||||
$h = (int)$flights[$flightId]->start_hole;
|
||||
$holeHighLikeLoad[$h] = ($holeHighLikeLoad[$h] ?? 0) + 1;
|
||||
}
|
||||
$this->refreshFlightStatus($flightId);
|
||||
|
||||
// reflect memory
|
||||
$flights[$flightId]->members->push((object)[ 'seat_no' => $seat, 'registration' => $r ]);
|
||||
}
|
||||
}
|
||||
|
||||
// refresh remaining regs
|
||||
$regs = $getPendingRegs();
|
||||
|
||||
// 3) BALANCED - now course_pref aware + hole bottleneck mitigation
|
||||
$balancedTarget = config('pxg.pairing.balanced_target', ['LOW','MID','MID','HIGH']);
|
||||
$maxHighLike = (int) config('pxg.pairing.max_high_like_per_flight', 2);
|
||||
|
||||
$balancedRegs = $regs->where('pairing_mode', 'BALANCED')->values();
|
||||
$pool = $this->poolByBand($balancedRegs);
|
||||
|
||||
// While there are regs, pick next reg to place and choose best flight for that reg band+course_pref
|
||||
while ($this->poolHasAny($pool)) {
|
||||
// pick next band by target cycle
|
||||
foreach ($balancedTarget as $needBand) {
|
||||
if (!$this->poolHasAny($pool)) break;
|
||||
|
||||
$needBand = strtoupper($needBand);
|
||||
$pickBand = $needBand;
|
||||
|
||||
if ($needBand === 'HIGH' && empty($pool['HIGH']) && !empty($pool['BEGINNER'])) $pickBand = 'BEGINNER';
|
||||
|
||||
$reg = $this->popFromPool($pool, $pickBand);
|
||||
if (!$reg) $reg = $this->popAny($pool);
|
||||
if (!$reg) break;
|
||||
|
||||
$coursePref = $reg->course_pref ?? 'ANY';
|
||||
$flightId = $this->findBestFlightForBalanced($flights, $flightSeats, $courseLoad, $holeHighLikeLoad, $reg, $coursePref);
|
||||
if (!$flightId) {
|
||||
// if semi-hard pref blocks, fallback ANY
|
||||
$flightId = $this->findBestFlightForBalanced($flights, $flightSeats, $courseLoad, $holeHighLikeLoad, $reg, 'ANY');
|
||||
}
|
||||
if (!$flightId) {
|
||||
// put back and stop
|
||||
$this->pushBack($pool, $reg);
|
||||
break;
|
||||
}
|
||||
|
||||
// Pace guardrail: avoid too many high-like in one flight
|
||||
$curHighLike = $this->countHighLikeInFlight($flights[$flightId]);
|
||||
if ($this->isHighLike($reg->handicap_band) && $curHighLike >= $maxHighLike) {
|
||||
$this->pushBack($pool, $reg);
|
||||
$alt = $this->popFirstNonHighLike($pool);
|
||||
if ($alt) $reg = $alt; else $reg = $this->popAny($pool) ?? $reg;
|
||||
}
|
||||
|
||||
if (empty($flightSeats[$flightId])) {
|
||||
// no seat left, retry next iteration
|
||||
$this->pushBack($pool, $reg);
|
||||
continue;
|
||||
}
|
||||
|
||||
$seat = array_shift($flightSeats[$flightId]);
|
||||
FlightMember::create([
|
||||
'flight_id' => $flightId,
|
||||
'registration_id' => $reg->id,
|
||||
'seat_no' => $seat,
|
||||
'lock_flag' => false,
|
||||
]);
|
||||
$assigned++;
|
||||
$courseLoad[$flights[$flightId]->course] = ($courseLoad[$flights[$flightId]->course] ?? 0) + 1;
|
||||
if ($this->isHighLike($reg->handicap_band)) {
|
||||
$h = (int)$flights[$flightId]->start_hole;
|
||||
$holeHighLikeLoad[$h] = ($holeHighLikeLoad[$h] ?? 0) + 1;
|
||||
}
|
||||
$this->refreshFlightStatus($flightId);
|
||||
|
||||
$flights[$flightId]->members->push((object)[ 'seat_no' => $seat, 'registration' => $reg ]);
|
||||
}
|
||||
}
|
||||
|
||||
// refresh remaining regs
|
||||
$regs = $getPendingRegs();
|
||||
|
||||
// 4) RANDOM - course_pref semi-hard + course balance
|
||||
$randomRegs = $regs->where('pairing_mode', 'RANDOM')->values();
|
||||
foreach ($randomRegs as $r) {
|
||||
$flightId = $this->findBestFlightForRandom($flights, $flightSeats, $courseLoad, $holeHighLikeLoad, $r, $r->course_pref);
|
||||
if (!$flightId) $flightId = $this->findBestFlightForRandom($flights, $flightSeats, $courseLoad, $holeHighLikeLoad, $r, 'ANY');
|
||||
if (!$flightId) break;
|
||||
|
||||
$seat = array_shift($flightSeats[$flightId]);
|
||||
FlightMember::create([
|
||||
'flight_id' => $flightId,
|
||||
'registration_id' => $r->id,
|
||||
'seat_no' => $seat,
|
||||
'lock_flag' => false,
|
||||
]);
|
||||
$assigned++;
|
||||
$courseLoad[$flights[$flightId]->course] = ($courseLoad[$flights[$flightId]->course] ?? 0) + 1;
|
||||
if ($this->isHighLike($r->handicap_band)) {
|
||||
$h = (int)$flights[$flightId]->start_hole;
|
||||
$holeHighLikeLoad[$h] = ($holeHighLikeLoad[$h] ?? 0) + 1;
|
||||
}
|
||||
$this->refreshFlightStatus($flightId);
|
||||
|
||||
$flights[$flightId]->members->push((object)[ 'seat_no' => $seat, 'registration' => $r ]);
|
||||
}
|
||||
|
||||
return ['assigned' => $assigned, 'notes' => $notes];
|
||||
});
|
||||
}
|
||||
|
||||
private function computeCourseLoad(int $eventId): array
|
||||
{
|
||||
$rows = DB::table('flight_members')
|
||||
->join('flights', 'flight_members.flight_id', '=', 'flights.id')
|
||||
->where('flights.event_id', $eventId)
|
||||
->select('flights.course', DB::raw('count(*) as cnt'))
|
||||
->groupBy('flights.course')
|
||||
->get();
|
||||
|
||||
$load = ['A' => 0, 'B' => 0];
|
||||
foreach ($rows as $r) $load[$r->course] = (int) $r->cnt;
|
||||
return $load;
|
||||
}
|
||||
|
||||
private function computeHoleHighLikeLoad(int $eventId): array
|
||||
{
|
||||
// count HIGH+BEGINNER assigned per start_hole across courses (shotgun bottleneck proxy)
|
||||
$rows = DB::table('flight_members')
|
||||
->join('flights', 'flight_members.flight_id', '=', 'flights.id')
|
||||
->join('registrations', 'flight_members.registration_id', '=', 'registrations.id')
|
||||
->where('flights.event_id', $eventId)
|
||||
->whereIn('registrations.handicap_band', ['HIGH','BEGINNER'])
|
||||
->select('flights.start_hole', DB::raw('count(*) as cnt'))
|
||||
->groupBy('flights.start_hole')
|
||||
->get();
|
||||
|
||||
$load = [];
|
||||
foreach ($rows as $r) $load[(int)$r->start_hole] = (int) $r->cnt;
|
||||
return $load;
|
||||
}
|
||||
|
||||
private function refreshFlightStatus(int $flightId): void
|
||||
{
|
||||
$count = FlightMember::where('flight_id', $flightId)->count();
|
||||
Flight::where('id', $flightId)->update(['status' => $count >= 4 ? 'FULL' : 'OPEN']);
|
||||
}
|
||||
|
||||
private function isHighLike(?string $band): bool
|
||||
{
|
||||
$b = strtoupper((string)$band);
|
||||
return $b === 'HIGH' || $b === 'BEGINNER';
|
||||
}
|
||||
|
||||
private function countHighLikeInFlight(Flight $flight): int
|
||||
{
|
||||
$c = 0;
|
||||
foreach ($flight->members as $m) {
|
||||
$b = $m->registration?->handicap_band ?? null;
|
||||
if ($this->isHighLike($b)) $c++;
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
|
||||
private function findEmptyFlightBalanced($flights, $flightSeats, array $courseLoad, string $coursePref): ?int
|
||||
{
|
||||
$candidates = [];
|
||||
foreach ($flights as $f) {
|
||||
if (($f->members->count() ?? 0) !== 0) continue;
|
||||
if (count($flightSeats[$f->id] ?? []) !== 4) continue;
|
||||
if (in_array($coursePref, ['A','B']) && $f->course !== $coursePref) continue;
|
||||
$candidates[] = $f;
|
||||
}
|
||||
if (empty($candidates)) {
|
||||
if ($coursePref !== 'ANY') return $this->findEmptyFlightBalanced($flights, $flightSeats, $courseLoad, 'ANY');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!config('pxg.pairing.course_balance', true)) return $candidates[0]->id;
|
||||
|
||||
usort($candidates, fn($a,$b) => ($courseLoad[$a->course] ?? 0) <=> ($courseLoad[$b->course] ?? 0));
|
||||
return $candidates[0]->id;
|
||||
}
|
||||
|
||||
private function findBestFlightForLevel($flights, $flightSeats, array $courseLoad, array $holeHighLikeLoad, string $band, string $coursePref): ?int
|
||||
{
|
||||
// Semi-hard course preference: if preferred has any seats at all, do not choose other course.
|
||||
if (config('pxg.pairing.course_pref_semi_hard', true) && in_array($coursePref, ['A','B'])) {
|
||||
if ($this->courseHasSeats($flights, $flightSeats, $coursePref)) {
|
||||
return $this->findBestFlightForLevel($flights, $flightSeats, $courseLoad, $holeHighLikeLoad, $band, $coursePref === 'A' ? 'A' : 'B');
|
||||
}
|
||||
// else fallback ANY below
|
||||
$coursePref = 'ANY';
|
||||
}
|
||||
|
||||
$band = strtoupper($band);
|
||||
$candidates = [];
|
||||
|
||||
foreach ($flights as $f) {
|
||||
if (empty($flightSeats[$f->id] ?? [])) continue;
|
||||
if (in_array($coursePref, ['A','B']) && $f->course !== $coursePref) continue;
|
||||
|
||||
$bands = $f->members->map(fn($m)=> strtoupper((string)($m->registration?->handicap_band)))->filter()->values()->all();
|
||||
$unique = array_values(array_unique($bands));
|
||||
$isHomogeneousSame = (count($unique) === 1 && $unique[0] === $band);
|
||||
|
||||
$count = count($bands);
|
||||
$score = 0;
|
||||
if ($isHomogeneousSame) $score += 140;
|
||||
if ($count === 0) $score += 80;
|
||||
$score += (4 - $count) * 6;
|
||||
|
||||
if (config('pxg.pairing.course_balance', true) && $coursePref === 'ANY') {
|
||||
$score += (200 - ($courseLoad[$f->course] ?? 0));
|
||||
}
|
||||
|
||||
// If assigning HIGH/BEGINNER in level mode, spread across holes
|
||||
if (config('pxg.pairing.hole_balance_high_like', true) && $this->isHighLike($band)) {
|
||||
$pen = (int) config('pxg.pairing.hole_high_like_penalty', 12);
|
||||
$score -= ($holeHighLikeLoad[(int)$f->start_hole] ?? 0) * $pen;
|
||||
}
|
||||
|
||||
$candidates[] = [$f->id, $score];
|
||||
}
|
||||
|
||||
if (empty($candidates)) {
|
||||
if ($coursePref !== 'ANY') return $this->findBestFlightForLevel($flights, $flightSeats, $courseLoad, $holeHighLikeLoad, $band, 'ANY');
|
||||
return null;
|
||||
}
|
||||
|
||||
usort($candidates, fn($x,$y) => $y[1] <=> $x[1]);
|
||||
return $candidates[0][0];
|
||||
}
|
||||
|
||||
private function findBestFlightForBalanced($flights, $flightSeats, array $courseLoad, array $holeHighLikeLoad, Registration $reg, string $coursePref): ?int
|
||||
{
|
||||
// semi-hard course preference
|
||||
if (config('pxg.pairing.course_pref_semi_hard', true) && in_array($coursePref, ['A','B'])) {
|
||||
if ($this->courseHasSeats($flights, $flightSeats, $coursePref)) {
|
||||
// keep pref
|
||||
} else {
|
||||
$coursePref = 'ANY';
|
||||
}
|
||||
}
|
||||
|
||||
$candidates = [];
|
||||
$isHigh = $this->isHighLike($reg->handicap_band);
|
||||
|
||||
foreach ($flights as $f) {
|
||||
if (empty($flightSeats[$f->id] ?? [])) continue;
|
||||
if (in_array($coursePref, ['A','B']) && $f->course !== $coursePref) continue;
|
||||
|
||||
$count = $f->members->count();
|
||||
$score = (4 - $count) * 12;
|
||||
|
||||
// Avoid flights with many high-like already
|
||||
$score -= $this->countHighLikeInFlight($f) * 10;
|
||||
|
||||
if (config('pxg.pairing.course_balance', true) && $coursePref === 'ANY') {
|
||||
$score += (200 - ($courseLoad[$f->course] ?? 0));
|
||||
}
|
||||
|
||||
if (config('pxg.pairing.hole_balance_high_like', true) && $isHigh) {
|
||||
$pen = (int) config('pxg.pairing.hole_high_like_penalty', 12);
|
||||
$score -= ($holeHighLikeLoad[(int)$f->start_hole] ?? 0) * $pen;
|
||||
}
|
||||
|
||||
$candidates[] = [$f->id, $score];
|
||||
}
|
||||
|
||||
if (empty($candidates)) return null;
|
||||
usort($candidates, fn($x,$y) => $y[1] <=> $x[1]);
|
||||
return $candidates[0][0];
|
||||
}
|
||||
|
||||
private function findBestFlightForRandom($flights, $flightSeats, array $courseLoad, array $holeHighLikeLoad, Registration $reg, string $coursePref): ?int
|
||||
{
|
||||
if (config('pxg.pairing.course_pref_semi_hard', true) && in_array($coursePref, ['A','B'])) {
|
||||
if (!$this->courseHasSeats($flights, $flightSeats, $coursePref)) $coursePref = 'ANY';
|
||||
}
|
||||
|
||||
$candidates = [];
|
||||
$isHigh = $this->isHighLike($reg->handicap_band);
|
||||
|
||||
foreach ($flights as $f) {
|
||||
if (empty($flightSeats[$f->id] ?? [])) continue;
|
||||
if (in_array($coursePref, ['A','B']) && $f->course !== $coursePref) continue;
|
||||
|
||||
$count = $f->members->count();
|
||||
$score = (4 - $count) * 20;
|
||||
|
||||
if (config('pxg.pairing.course_balance', true) && $coursePref === 'ANY') {
|
||||
$score += (200 - ($courseLoad[$f->course] ?? 0));
|
||||
}
|
||||
|
||||
if (config('pxg.pairing.hole_balance_high_like', true) && $isHigh) {
|
||||
$pen = (int) config('pxg.pairing.hole_high_like_penalty', 12);
|
||||
$score -= ($holeHighLikeLoad[(int)$f->start_hole] ?? 0) * $pen;
|
||||
}
|
||||
|
||||
$candidates[] = [$f->id, $score];
|
||||
}
|
||||
|
||||
if (empty($candidates)) return null;
|
||||
usort($candidates, fn($x,$y) => $y[1] <=> $x[1]);
|
||||
return $candidates[0][0];
|
||||
}
|
||||
|
||||
private function courseHasSeats($flights, $flightSeats, string $course): bool
|
||||
{
|
||||
foreach ($flights as $f) {
|
||||
if ($f->course !== $course) continue;
|
||||
if (!empty($flightSeats[$f->id] ?? [])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function poolByBand($regs): array
|
||||
{
|
||||
$pool = ['LOW'=>[], 'MID'=>[], 'HIGH'=>[], 'BEGINNER'=>[]];
|
||||
foreach ($regs as $r) {
|
||||
$b = strtoupper((string)($r->handicap_band ?? 'MID'));
|
||||
if (!isset($pool[$b])) $pool[$b] = [];
|
||||
$pool[$b][] = $r;
|
||||
}
|
||||
return $pool;
|
||||
}
|
||||
|
||||
private function poolHasAny(array $pool): bool
|
||||
{
|
||||
foreach ($pool as $arr) if (!empty($arr)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private function popFromPool(array &$pool, string $band): ?Registration
|
||||
{
|
||||
$band = strtoupper($band);
|
||||
if (empty($pool[$band])) return null;
|
||||
return array_shift($pool[$band]);
|
||||
}
|
||||
|
||||
private function popAny(array &$pool): ?Registration
|
||||
{
|
||||
foreach (['LOW','MID','HIGH','BEGINNER'] as $b) if (!empty($pool[$b])) return array_shift($pool[$b]);
|
||||
return null;
|
||||
}
|
||||
|
||||
private function pushBack(array &$pool, Registration $r): void
|
||||
{
|
||||
$b = strtoupper((string)($r->handicap_band ?? 'MID'));
|
||||
$pool[$b][] = $r;
|
||||
}
|
||||
|
||||
private function popFirstNonHighLike(array &$pool): ?Registration
|
||||
{
|
||||
foreach (['LOW','MID'] as $b) if (!empty($pool[$b])) return array_shift($pool[$b]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
||||
class PairingTokenService
|
||||
{
|
||||
public function issue(int $registrationId): string
|
||||
{
|
||||
$ttl = config('pxg.pairing_token_ttl_minutes', 30);
|
||||
$payload = [
|
||||
'rid' => $registrationId,
|
||||
'exp' => now()->addMinutes($ttl)->timestamp,
|
||||
];
|
||||
return Crypt::encryptString(json_encode($payload));
|
||||
}
|
||||
|
||||
public function verify(string $token): ?int
|
||||
{
|
||||
try {
|
||||
$json = Crypt::decryptString($token);
|
||||
$payload = json_decode($json, true);
|
||||
if (!is_array($payload)) return null;
|
||||
if (($payload['exp'] ?? 0) < time()) return null;
|
||||
$rid = (int) ($payload['rid'] ?? 0);
|
||||
return $rid > 0 ? $rid : null;
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class RegistrationCodeService
|
||||
{
|
||||
public function make(): string
|
||||
{
|
||||
// REG-XXXXXX (base32-ish)
|
||||
$alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
||||
$s = '';
|
||||
for ($i=0;$i<5;$i++){
|
||||
$s .= $alphabet[random_int(0, strlen($alphabet)-1)];
|
||||
}
|
||||
return 'REG-' . $s;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\PaymentIntent;
|
||||
use App\Models\Registration;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class XenditService
|
||||
{
|
||||
/**
|
||||
* Replace with real Xendit Invoice API call.
|
||||
* Return:
|
||||
* - provider_ref_id (invoice id)
|
||||
* - checkout_url
|
||||
*/
|
||||
public function createInvoice(PaymentIntent $intent, Registration $registration): array
|
||||
{
|
||||
// TODO: call Xendit Invoice API using XENDIT_API_KEY
|
||||
// For now: stub response
|
||||
$providerRefId = 'inv_stub_' . $intent->id;
|
||||
$checkoutUrl = 'https://checkout.xendit.co/web/' . $providerRefId;
|
||||
|
||||
return [
|
||||
'provider_ref_id' => $providerRefId,
|
||||
'checkout_url' => $checkoutUrl,
|
||||
'raw_payload' => [
|
||||
'stub' => true,
|
||||
'intent_id' => $intent->id,
|
||||
'registration_id' => $registration->id
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimal webhook verification using a shared token (recommended baseline).
|
||||
* Configure `XENDIT_WEBHOOK_TOKEN` in .env and set the same token in Xendit dashboard.
|
||||
*/
|
||||
public function verifyWebhook(Request $request): bool
|
||||
{
|
||||
$expected = config('pxg.xendit.webhook_token', '');
|
||||
if (!$expected) return true; // allow in dev
|
||||
|
||||
// Xendit commonly uses X-Callback-Token for invoice callbacks.
|
||||
$got = $request->header('X-Callback-Token') ?? $request->header('x-callback-token');
|
||||
return is_string($got) && hash_equals($expected, $got);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
define('LARAVEL_START', microtime(true));
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register The Auto Loader
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Composer provides a convenient, automatically generated class loader
|
||||
| for our application. We just need to utilize it! We'll require it
|
||||
| into the script here so that we do not have to worry about the
|
||||
| loading of any of our classes manually. It's great to relax.
|
||||
|
|
||||
*/
|
||||
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
|
||||
$app = require_once __DIR__.'/bootstrap/app.php';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Run The Artisan Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When we run the console application, the current CLI command will be
|
||||
| executed in this console and the response sent back to a terminal
|
||||
| or another output device for the developers. Here goes nothing!
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
||||
|
||||
$status = $kernel->handle(
|
||||
$input = new Symfony\Component\Console\Input\ArgvInput,
|
||||
new Symfony\Component\Console\Output\ConsoleOutput
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Shutdown The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Once Artisan has finished running, we will fire off the shutdown events
|
||||
| so that any final work may be done by the application before we shut
|
||||
| down the process. This is the last thing to happen to the request.
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel->terminate($input, $status);
|
||||
|
||||
exit($status);
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Create The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The first thing we will do is create a new Laravel application instance
|
||||
| which serves as the "glue" for all the components of Laravel, and is
|
||||
| the IoC container for the system binding all of the various parts.
|
||||
|
|
||||
*/
|
||||
|
||||
$app = new Illuminate\Foundation\Application(
|
||||
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bind Important Interfaces
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, we need to bind some important interfaces into the container so
|
||||
| we will be able to resolve them when needed. The kernels serve the
|
||||
| incoming requests to this application from both the web and CLI.
|
||||
|
|
||||
*/
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Http\Kernel::class,
|
||||
App\Http\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Console\Kernel::class,
|
||||
App\Console\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Debug\ExceptionHandler::class,
|
||||
App\Exceptions\Handler::class
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Return The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This script returns the application instance. The instance is given to
|
||||
| the calling script so we can separate the building of the instances
|
||||
| from the actual running of the application and sending responses.
|
||||
|
|
||||
*/
|
||||
|
||||
return $app;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"name": "laravel/laravel",
|
||||
"type": "project",
|
||||
"description": "The skeleton application for the Laravel framework.",
|
||||
"keywords": ["laravel", "framework"],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"guzzlehttp/guzzle": "^7.2",
|
||||
"laravel/framework": "^10.10",
|
||||
"laravel/sanctum": "^3.3",
|
||||
"laravel/tinker": "^2.8"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.9.1",
|
||||
"laravel/pint": "^1.0",
|
||||
"laravel/sail": "^1.18",
|
||||
"mockery/mockery": "^1.4.4",
|
||||
"nunomaduro/collision": "^7.0",
|
||||
"phpunit/phpunit": "^10.1",
|
||||
"spatie/laravel-ignition": "^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-autoload-dump": [
|
||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||
"@php artisan package:discover --ansi"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
||||
],
|
||||
"post-root-package-install": [
|
||||
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||
],
|
||||
"post-create-project-cmd": [
|
||||
"@php artisan key:generate --ansi"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"dont-discover": []
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true,
|
||||
"php-http/discovery": true
|
||||
}
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"prefer-stable": true
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value is the name of your application. This value is used when the
|
||||
| framework needs to place the application's name in a notification or
|
||||
| any other location as required by the application or its packages.
|
||||
|
|
||||
*/
|
||||
|
||||
'name' => env('APP_NAME', 'Laravel'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Environment
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the "environment" your application is currently
|
||||
| running in. This may determine how you prefer to configure various
|
||||
| services the application utilizes. Set this in your ".env" file.
|
||||
|
|
||||
*/
|
||||
|
||||
'env' => env('APP_ENV', 'production'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Debug Mode
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When your application is in debug mode, detailed error messages with
|
||||
| stack traces will be shown on every error that occurs within your
|
||||
| application. If disabled, a simple generic error page is shown.
|
||||
|
|
||||
*/
|
||||
|
||||
'debug' => (bool) env('APP_DEBUG', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application URL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This URL is used by the console to properly generate URLs when using
|
||||
| the Artisan command line tool. You should set this to the root of
|
||||
| your application so that it is used when running Artisan tasks.
|
||||
|
|
||||
*/
|
||||
|
||||
'url' => env('APP_URL', 'http://localhost'),
|
||||
|
||||
'asset_url' => env('ASSET_URL'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Timezone
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default timezone for your application, which
|
||||
| will be used by the PHP date and date-time functions. We have gone
|
||||
| ahead and set this to a sensible default for you out of the box.
|
||||
|
|
||||
*/
|
||||
|
||||
'timezone' => 'UTC',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Locale Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The application locale determines the default locale that will be used
|
||||
| by the translation service provider. You are free to set this value
|
||||
| to any of the locales which will be supported by the application.
|
||||
|
|
||||
*/
|
||||
|
||||
'locale' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Fallback Locale
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The fallback locale determines the locale to use when the current one
|
||||
| is not available. You may change the value to correspond to any of
|
||||
| the language folders that are provided through your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'fallback_locale' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Faker Locale
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This locale will be used by the Faker PHP library when generating fake
|
||||
| data for your database seeds. For example, this will be used to get
|
||||
| localized telephone numbers, street address information and more.
|
||||
|
|
||||
*/
|
||||
|
||||
'faker_locale' => 'en_US',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Encryption Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This key is used by the Illuminate encrypter service and should be set
|
||||
| to a random, 32 character string, otherwise these encrypted strings
|
||||
| will not be safe. Please do this before deploying an application!
|
||||
|
|
||||
*/
|
||||
|
||||
'key' => env('APP_KEY'),
|
||||
|
||||
'cipher' => 'AES-256-CBC',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Maintenance Mode Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These configuration options determine the driver used to determine and
|
||||
| manage Laravel's "maintenance mode" status. The "cache" driver will
|
||||
| allow maintenance mode to be controlled across multiple machines.
|
||||
|
|
||||
| Supported drivers: "file", "cache"
|
||||
|
|
||||
*/
|
||||
|
||||
'maintenance' => [
|
||||
'driver' => 'file',
|
||||
// 'store' => 'redis',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Autoloaded Service Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The service providers listed here will be automatically loaded on the
|
||||
| request to your application. Feel free to add your own services to
|
||||
| this array to grant expanded functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => ServiceProvider::defaultProviders()->merge([
|
||||
/*
|
||||
* Package Service Providers...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Application Service Providers...
|
||||
*/
|
||||
App\Providers\AppServiceProvider::class,
|
||||
App\Providers\AuthServiceProvider::class,
|
||||
// App\Providers\BroadcastServiceProvider::class,
|
||||
App\Providers\EventServiceProvider::class,
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
|
||||
App\Providers\PxgServiceProvider::class,
|
||||
])->toArray(),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Class Aliases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This array of class aliases will be registered when this application
|
||||
| is started. However, feel free to register as many as you wish as
|
||||
| the aliases are "lazy" loaded so they don't hinder performance.
|
||||
|
|
||||
*/
|
||||
|
||||
'aliases' => Facade::defaultAliases()->merge([
|
||||
// 'Example' => App\Facades\Example::class,
|
||||
])->toArray(),
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Defaults
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default authentication "guard" and password
|
||||
| reset options for your application. You may change these defaults
|
||||
| as required, but they're a perfect start for most applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'defaults' => [
|
||||
'guard' => 'web',
|
||||
'passwords' => 'users',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, you may define every authentication guard for your application.
|
||||
| Of course, a great default configuration has been defined for you
|
||||
| here which uses session storage and the Eloquent user provider.
|
||||
|
|
||||
| All authentication drivers have a user provider. This defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| mechanisms used by this application to persist your user's data.
|
||||
|
|
||||
| Supported: "session"
|
||||
|
|
||||
*/
|
||||
|
||||
'guards' => [
|
||||
'web' => [
|
||||
'driver' => 'session',
|
||||
'provider' => 'users',
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| User Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| All authentication drivers have a user provider. This defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| mechanisms used by this application to persist your user's data.
|
||||
|
|
||||
| If you have multiple user tables or models you may configure multiple
|
||||
| sources which represent each model / table. These sources may then
|
||||
| be assigned to any extra authentication guards you have defined.
|
||||
|
|
||||
| Supported: "database", "eloquent"
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => App\Models\User::class,
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
// 'driver' => 'database',
|
||||
// 'table' => 'users',
|
||||
// ],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Resetting Passwords
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may specify multiple password reset configurations if you have more
|
||||
| than one user table or model in the application and you want to have
|
||||
| separate password reset settings based on the specific user types.
|
||||
|
|
||||
| The expiry time is the number of minutes that each reset token will be
|
||||
| considered valid. This security feature keeps tokens short-lived so
|
||||
| they have less time to be guessed. You may change this as needed.
|
||||
|
|
||||
| The throttle setting is the number of seconds a user must wait before
|
||||
| generating more password reset tokens. This prevents the user from
|
||||
| quickly generating a very large amount of password reset tokens.
|
||||
|
|
||||
*/
|
||||
|
||||
'passwords' => [
|
||||
'users' => [
|
||||
'provider' => 'users',
|
||||
'table' => 'password_reset_tokens',
|
||||
'expire' => 60,
|
||||
'throttle' => 60,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Confirmation Timeout
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define the amount of seconds before a password confirmation
|
||||
| times out and the user is prompted to re-enter their password via the
|
||||
| confirmation screen. By default, the timeout lasts for three hours.
|
||||
|
|
||||
*/
|
||||
|
||||
'password_timeout' => 10800,
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Broadcaster
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default broadcaster that will be used by the
|
||||
| framework when an event needs to be broadcast. You may set this to
|
||||
| any of the connections defined in the "connections" array below.
|
||||
|
|
||||
| Supported: "pusher", "ably", "redis", "log", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('BROADCAST_DRIVER', 'null'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Broadcast Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the broadcast connections that will be used
|
||||
| to broadcast events to other systems or over websockets. Samples of
|
||||
| each available type of connection are provided inside this array.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'pusher' => [
|
||||
'driver' => 'pusher',
|
||||
'key' => env('PUSHER_APP_KEY'),
|
||||
'secret' => env('PUSHER_APP_SECRET'),
|
||||
'app_id' => env('PUSHER_APP_ID'),
|
||||
'options' => [
|
||||
'cluster' => env('PUSHER_APP_CLUSTER'),
|
||||
'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com',
|
||||
'port' => env('PUSHER_PORT', 443),
|
||||
'scheme' => env('PUSHER_SCHEME', 'https'),
|
||||
'encrypted' => true,
|
||||
'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
|
||||
],
|
||||
'client_options' => [
|
||||
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
|
||||
],
|
||||
],
|
||||
|
||||
'ably' => [
|
||||
'driver' => 'ably',
|
||||
'key' => env('ABLY_KEY'),
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'driver' => 'log',
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'null',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default cache connection that gets used while
|
||||
| using this caching library. This connection is used when another is
|
||||
| not explicitly specified when executing a given caching function.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('CACHE_DRIVER', 'file'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Stores
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the cache "stores" for your application as
|
||||
| well as their drivers. You may even define multiple stores for the
|
||||
| same cache driver to group types of items stored in your caches.
|
||||
|
|
||||
| Supported drivers: "apc", "array", "database", "file",
|
||||
| "memcached", "redis", "dynamodb", "octane", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'stores' => [
|
||||
|
||||
'apc' => [
|
||||
'driver' => 'apc',
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'driver' => 'array',
|
||||
'serialize' => false,
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'table' => 'cache',
|
||||
'connection' => null,
|
||||
'lock_connection' => null,
|
||||
],
|
||||
|
||||
'file' => [
|
||||
'driver' => 'file',
|
||||
'path' => storage_path('framework/cache/data'),
|
||||
'lock_path' => storage_path('framework/cache/data'),
|
||||
],
|
||||
|
||||
'memcached' => [
|
||||
'driver' => 'memcached',
|
||||
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
|
||||
'sasl' => [
|
||||
env('MEMCACHED_USERNAME'),
|
||||
env('MEMCACHED_PASSWORD'),
|
||||
],
|
||||
'options' => [
|
||||
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
|
||||
],
|
||||
'servers' => [
|
||||
[
|
||||
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
|
||||
'port' => env('MEMCACHED_PORT', 11211),
|
||||
'weight' => 100,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'cache',
|
||||
'lock_connection' => 'default',
|
||||
],
|
||||
|
||||
'dynamodb' => [
|
||||
'driver' => 'dynamodb',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
|
||||
'endpoint' => env('DYNAMODB_ENDPOINT'),
|
||||
],
|
||||
|
||||
'octane' => [
|
||||
'driver' => 'octane',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Key Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When utilizing the APC, database, memcached, Redis, or DynamoDB cache
|
||||
| stores there might be other applications using the same cache. For
|
||||
| that reason, you may prefix every cache key to avoid collisions.
|
||||
|
|
||||
*/
|
||||
|
||||
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cross-Origin Resource Sharing (CORS) Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure your settings for cross-origin resource sharing
|
||||
| or "CORS". This determines what cross-origin operations may execute
|
||||
| in web browsers. You are free to adjust these settings as needed.
|
||||
|
|
||||
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||
|
|
||||
*/
|
||||
|
||||
'paths' => ['api/*', 'sanctum/csrf-cookie'],
|
||||
|
||||
'allowed_methods' => ['*'],
|
||||
|
||||
'allowed_origins' => array_values(array_filter(array_map('trim', explode(',', env('CORS_ALLOWED_ORIGINS', 'http://localhost:5173,http://127.0.0.1:5173'))))),
|
||||
|
||||
'allowed_origins_patterns' => array_values(array_filter(array_map('trim', explode(',', env('CORS_ALLOWED_ORIGIN_PATTERNS', '#^https?://(localhost|127\\.0\\.0\\.1)(:\\d+)?$#'))))),
|
||||
|
||||
'allowed_headers' => ['*'],
|
||||
|
||||
'exposed_headers' => [],
|
||||
|
||||
'max_age' => 0,
|
||||
|
||||
'supports_credentials' => env('CORS_SUPPORTS_CREDENTIALS', false),
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Database Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify which of the database connections below you wish
|
||||
| to use as your default connection for all database work. Of course
|
||||
| you may use many connections at once using the Database library.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('DB_CONNECTION', 'mysql'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Database Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here are each of the database connections setup for your application.
|
||||
| Of course, examples of configuring each database platform that is
|
||||
| supported by Laravel is shown below to make development simple.
|
||||
|
|
||||
|
|
||||
| All database work in Laravel is done through the PHP PDO facilities
|
||||
| so make sure you have the driver for your particular database of
|
||||
| choice installed on your machine before you begin development.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sqlite' => [
|
||||
'driver' => 'sqlite',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'database' => env('DB_DATABASE', database_path('database.sqlite')),
|
||||
'prefix' => '',
|
||||
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
|
||||
],
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '5432'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'search_path' => 'public',
|
||||
'sslmode' => 'prefer',
|
||||
],
|
||||
|
||||
'sqlsrv' => [
|
||||
'driver' => 'sqlsrv',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '1433'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
// 'encrypt' => env('DB_ENCRYPT', 'yes'),
|
||||
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migration Repository Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This table keeps track of all the migrations that have already run for
|
||||
| your application. Using this information, we can determine which of
|
||||
| the migrations on disk haven't actually been run in the database.
|
||||
|
|
||||
*/
|
||||
|
||||
'migrations' => 'migrations',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Redis Databases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Redis is an open source, fast, and advanced key-value store that also
|
||||
| provides a richer body of commands than a typical key-value system
|
||||
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
||||
|
|
||||
*/
|
||||
|
||||
'redis' => [
|
||||
|
||||
'client' => env('REDIS_CLIENT', 'phpredis'),
|
||||
|
||||
'options' => [
|
||||
'cluster' => env('REDIS_CLUSTER', 'redis'),
|
||||
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
|
||||
],
|
||||
|
||||
'default' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_DB', '0'),
|
||||
],
|
||||
|
||||
'cache' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_CACHE_DB', '1'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Filesystem Disk
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default filesystem disk that should be used
|
||||
| by the framework. The "local" disk, as well as a variety of cloud
|
||||
| based disks are available to your application. Just store away!
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('FILESYSTEM_DISK', 'local'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filesystem Disks
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure as many filesystem "disks" as you wish, and you
|
||||
| may even configure multiple disks of the same driver. Defaults have
|
||||
| been set up for each driver as an example of the required values.
|
||||
|
|
||||
| Supported Drivers: "local", "ftp", "sftp", "s3"
|
||||
|
|
||||
*/
|
||||
|
||||
'disks' => [
|
||||
|
||||
'local' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app'),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
'public' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'visibility' => 'public',
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
's3' => [
|
||||
'driver' => 's3',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION'),
|
||||
'bucket' => env('AWS_BUCKET'),
|
||||
'url' => env('AWS_URL'),
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Symbolic Links
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the symbolic links that will be created when the
|
||||
| `storage:link` Artisan command is executed. The array keys should be
|
||||
| the locations of the links and the values should be their targets.
|
||||
|
|
||||
*/
|
||||
|
||||
'links' => [
|
||||
public_path('storage') => storage_path('app/public'),
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Hash Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default hash driver that will be used to hash
|
||||
| passwords for your application. By default, the bcrypt algorithm is
|
||||
| used; however, you remain free to modify this option if you wish.
|
||||
|
|
||||
| Supported: "bcrypt", "argon", "argon2id"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => 'bcrypt',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bcrypt Options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the configuration options that should be used when
|
||||
| passwords are hashed using the Bcrypt algorithm. This will allow you
|
||||
| to control the amount of time it takes to hash the given password.
|
||||
|
|
||||
*/
|
||||
|
||||
'bcrypt' => [
|
||||
'rounds' => env('BCRYPT_ROUNDS', 12),
|
||||
'verify' => true,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Argon Options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the configuration options that should be used when
|
||||
| passwords are hashed using the Argon algorithm. These will allow you
|
||||
| to control the amount of time it takes to hash the given password.
|
||||
|
|
||||
*/
|
||||
|
||||
'argon' => [
|
||||
'memory' => 65536,
|
||||
'threads' => 1,
|
||||
'time' => 4,
|
||||
'verify' => true,
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
use Monolog\Handler\NullHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Handler\SyslogUdpHandler;
|
||||
use Monolog\Processor\PsrLogMessageProcessor;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the default log channel that gets used when writing
|
||||
| messages to the logs. The name specified in this option should match
|
||||
| one of the channels defined in the "channels" configuration array.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('LOG_CHANNEL', 'stack'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Deprecations Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the log channel that should be used to log warnings
|
||||
| regarding deprecated PHP and library features. This allows you to get
|
||||
| your application ready for upcoming major versions of dependencies.
|
||||
|
|
||||
*/
|
||||
|
||||
'deprecations' => [
|
||||
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
|
||||
'trace' => false,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Log Channels
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the log channels for your application. Out of
|
||||
| the box, Laravel uses the Monolog PHP logging library. This gives
|
||||
| you a variety of powerful log handlers / formatters to utilize.
|
||||
|
|
||||
| Available Drivers: "single", "daily", "slack", "syslog",
|
||||
| "errorlog", "monolog",
|
||||
| "custom", "stack"
|
||||
|
|
||||
*/
|
||||
|
||||
'channels' => [
|
||||
'stack' => [
|
||||
'driver' => 'stack',
|
||||
'channels' => ['single'],
|
||||
'ignore_exceptions' => false,
|
||||
],
|
||||
|
||||
'single' => [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'daily' => [
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'days' => 14,
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
'driver' => 'slack',
|
||||
'url' => env('LOG_SLACK_WEBHOOK_URL'),
|
||||
'username' => 'Laravel Log',
|
||||
'emoji' => ':boom:',
|
||||
'level' => env('LOG_LEVEL', 'critical'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'papertrail' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
|
||||
'handler_with' => [
|
||||
'host' => env('PAPERTRAIL_URL'),
|
||||
'port' => env('PAPERTRAIL_PORT'),
|
||||
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'stderr' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => StreamHandler::class,
|
||||
'formatter' => env('LOG_STDERR_FORMATTER'),
|
||||
'with' => [
|
||||
'stream' => 'php://stderr',
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'syslog' => [
|
||||
'driver' => 'syslog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'facility' => LOG_USER,
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'errorlog' => [
|
||||
'driver' => 'errorlog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'monolog',
|
||||
'handler' => NullHandler::class,
|
||||
],
|
||||
|
||||
'emergency' => [
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Mailer
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default mailer that is used to send any email
|
||||
| messages sent by your application. Alternative mailers may be setup
|
||||
| and used as needed; however, this mailer will be used by default.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('MAIL_MAILER', 'smtp'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Mailer Configurations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure all of the mailers used by your application plus
|
||||
| their respective settings. Several examples have been configured for
|
||||
| you and you are free to add your own as your application requires.
|
||||
|
|
||||
| Laravel supports a variety of mail "transport" drivers to be used while
|
||||
| sending an e-mail. You will specify which one you are using for your
|
||||
| mailers below. You are free to add additional mailers as required.
|
||||
|
|
||||
| Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
|
||||
| "postmark", "log", "array", "failover", "roundrobin"
|
||||
|
|
||||
*/
|
||||
|
||||
'mailers' => [
|
||||
'smtp' => [
|
||||
'transport' => 'smtp',
|
||||
'url' => env('MAIL_URL'),
|
||||
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
|
||||
'port' => env('MAIL_PORT', 587),
|
||||
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
|
||||
'username' => env('MAIL_USERNAME'),
|
||||
'password' => env('MAIL_PASSWORD'),
|
||||
'timeout' => null,
|
||||
'local_domain' => env('MAIL_EHLO_DOMAIN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'transport' => 'ses',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'transport' => 'postmark',
|
||||
// 'message_stream_id' => null,
|
||||
// 'client' => [
|
||||
// 'timeout' => 5,
|
||||
// ],
|
||||
],
|
||||
|
||||
'mailgun' => [
|
||||
'transport' => 'mailgun',
|
||||
// 'client' => [
|
||||
// 'timeout' => 5,
|
||||
// ],
|
||||
],
|
||||
|
||||
'sendmail' => [
|
||||
'transport' => 'sendmail',
|
||||
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'transport' => 'log',
|
||||
'channel' => env('MAIL_LOG_CHANNEL'),
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'transport' => 'array',
|
||||
],
|
||||
|
||||
'failover' => [
|
||||
'transport' => 'failover',
|
||||
'mailers' => [
|
||||
'smtp',
|
||||
'log',
|
||||
],
|
||||
],
|
||||
|
||||
'roundrobin' => [
|
||||
'transport' => 'roundrobin',
|
||||
'mailers' => [
|
||||
'ses',
|
||||
'postmark',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global "From" Address
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may wish for all e-mails sent by your application to be sent from
|
||||
| the same address. Here, you may specify a name and address that is
|
||||
| used globally for all e-mails that are sent by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'from' => [
|
||||
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
|
||||
'name' => env('MAIL_FROM_NAME', 'Example'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Markdown Mail Settings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If you are using Markdown based email rendering, you may configure your
|
||||
| theme and component paths here, allowing you to customize the design
|
||||
| of the emails. Or, you may simply stick with the Laravel defaults!
|
||||
|
|
||||
*/
|
||||
|
||||
'markdown' => [
|
||||
'theme' => 'default',
|
||||
|
||||
'paths' => [
|
||||
resource_path('views/vendor/mail'),
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'otp_ttl_minutes' => (int) env('OTP_TTL_MINUTES', 5),
|
||||
'otp_max_attempts' => (int) env('OTP_MAX_ATTEMPTS', 5),
|
||||
'otp_rate_limit_per_phone' => (int) env('OTP_RATE_LIMIT_PER_PHONE', 3), // per 10 minutes
|
||||
'pairing_token_ttl_minutes' => (int) env('PAIRING_TOKEN_TTL_MINUTES', 30),
|
||||
|
||||
'wa_otp_driver' => env('WA_OTP_DRIVER', 'log'),
|
||||
|
||||
'pairing' => [
|
||||
// Balanced target seats: 4 slots (BEGINNER treated as HIGH-like by default)
|
||||
'balanced_target' => ['LOW', 'MID', 'MID', 'HIGH'],
|
||||
|
||||
// Seat fill order
|
||||
'seat_order' => [1,2,3,4],
|
||||
|
||||
// Pace-of-play guardrails
|
||||
'max_high_like_per_flight' => 2,
|
||||
|
||||
// Course balancing: spread assigned seats across A/B unless course_pref is set
|
||||
'course_balance' => true,
|
||||
|
||||
// Semi-hard course preference:
|
||||
// true => always try preferred course first; only fallback if no seats exist on preferred.
|
||||
// false => treat as soft preference (score-based).
|
||||
'course_pref_semi_hard' => true,
|
||||
|
||||
// Hole bottleneck guardrail:
|
||||
// Distribute HIGH/BEGINNER across start holes (shotgun) to avoid stacking slow flights on same hole.
|
||||
'hole_balance_high_like' => true,
|
||||
// Penalty weight for assigning high-like players onto already high-like-heavy holes.
|
||||
'hole_high_like_penalty' => 12,
|
||||
],
|
||||
|
||||
'xendit' => [
|
||||
'api_key' => env('XENDIT_API_KEY', ''),
|
||||
'webhook_token' => env('XENDIT_WEBHOOK_TOKEN', ''),
|
||||
],
|
||||
];
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Queue Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Laravel's queue API supports an assortment of back-ends via a single
|
||||
| API, giving you convenient access to each back-end using the same
|
||||
| syntax for every one. Here you may define a default connection.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('QUEUE_CONNECTION', 'sync'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Queue Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the connection information for each server that
|
||||
| is used by your application. A default configuration has been added
|
||||
| for each back-end shipped with Laravel. You are free to add more.
|
||||
|
|
||||
| Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sync' => [
|
||||
'driver' => 'sync',
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'table' => 'jobs',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'beanstalkd' => [
|
||||
'driver' => 'beanstalkd',
|
||||
'host' => 'localhost',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'block_for' => 0,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'sqs' => [
|
||||
'driver' => 'sqs',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
|
||||
'queue' => env('SQS_QUEUE', 'default'),
|
||||
'suffix' => env('SQS_SUFFIX'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
'queue' => env('REDIS_QUEUE', 'default'),
|
||||
'retry_after' => 90,
|
||||
'block_for' => null,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Job Batching
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following options configure the database and table that store job
|
||||
| batching information. These options can be updated to any database
|
||||
| connection and table which has been defined by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'batching' => [
|
||||
'database' => env('DB_CONNECTION', 'mysql'),
|
||||
'table' => 'job_batches',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Failed Queue Jobs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These options configure the behavior of failed queue job logging so you
|
||||
| can control which database and table are used to store the jobs that
|
||||
| have failed. You may change them to any database / table you wish.
|
||||
|
|
||||
*/
|
||||
|
||||
'failed' => [
|
||||
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
|
||||
'database' => env('DB_CONNECTION', 'mysql'),
|
||||
'table' => 'failed_jobs',
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Stateful Domains
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Requests from the following domains / hosts will receive stateful API
|
||||
| authentication cookies. Typically, these should include your local
|
||||
| and production domains which access your API via a frontend SPA.
|
||||
|
|
||||
*/
|
||||
|
||||
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
|
||||
'%s%s',
|
||||
'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',
|
||||
Sanctum::currentApplicationUrlWithPort()
|
||||
))),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanctum Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This array contains the authentication guards that will be checked when
|
||||
| Sanctum is trying to authenticate a request. If none of these guards
|
||||
| are able to authenticate the request, Sanctum will use the bearer
|
||||
| token that's present on an incoming request for authentication.
|
||||
|
|
||||
*/
|
||||
|
||||
'guard' => ['web'],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expiration Minutes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value controls the number of minutes until an issued token will be
|
||||
| considered expired. This will override any values set in the token's
|
||||
| "expires_at" attribute, but first-party sessions are not affected.
|
||||
|
|
||||
*/
|
||||
|
||||
'expiration' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Token Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Sanctum can prefix new tokens in order to take advantage of numerous
|
||||
| security scanning initiatives maintained by open source platforms
|
||||
| that notify developers if they commit tokens into repositories.
|
||||
|
|
||||
| See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning
|
||||
|
|
||||
*/
|
||||
|
||||
'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanctum Middleware
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When authenticating your first-party SPA with Sanctum you may need to
|
||||
| customize some of the middleware Sanctum uses while processing the
|
||||
| request. You may change the middleware listed below as required.
|
||||
|
|
||||
*/
|
||||
|
||||
'middleware' => [
|
||||
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
|
||||
'encrypt_cookies' => App\Http\Middleware\EncryptCookies::class,
|
||||
'verify_csrf_token' => App\Http\Middleware\VerifyCsrfToken::class,
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Third Party Services
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This file is for storing the credentials for third party services such
|
||||
| as Mailgun, Postmark, AWS and more. This file provides the de facto
|
||||
| location for this type of information, allowing packages to have
|
||||
| a conventional file to locate the various service credentials.
|
||||
|
|
||||
*/
|
||||
|
||||
'mailgun' => [
|
||||
'domain' => env('MAILGUN_DOMAIN'),
|
||||
'secret' => env('MAILGUN_SECRET'),
|
||||
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
|
||||
'scheme' => 'https',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'token' => env('POSTMARK_TOKEN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Session Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default session "driver" that will be used on
|
||||
| requests. By default, we will use the lightweight native driver but
|
||||
| you may specify any of the other wonderful drivers provided here.
|
||||
|
|
||||
| Supported: "file", "cookie", "database", "apc",
|
||||
| "memcached", "redis", "dynamodb", "array"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => env('SESSION_DRIVER', 'file'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Lifetime
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the number of minutes that you wish the session
|
||||
| to be allowed to remain idle before it expires. If you want them
|
||||
| to immediately expire on the browser closing, set that option.
|
||||
|
|
||||
*/
|
||||
|
||||
'lifetime' => env('SESSION_LIFETIME', 120),
|
||||
|
||||
'expire_on_close' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Encryption
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option allows you to easily specify that all of your session data
|
||||
| should be encrypted before it is stored. All encryption will be run
|
||||
| automatically by Laravel and you can use the Session like normal.
|
||||
|
|
||||
*/
|
||||
|
||||
'encrypt' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session File Location
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the native session driver, we need a location where session
|
||||
| files may be stored. A default has been set for you but a different
|
||||
| location may be specified. This is only needed for file sessions.
|
||||
|
|
||||
*/
|
||||
|
||||
'files' => storage_path('framework/sessions'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Connection
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" or "redis" session drivers, you may specify a
|
||||
| connection that should be used to manage these sessions. This should
|
||||
| correspond to a connection in your database configuration options.
|
||||
|
|
||||
*/
|
||||
|
||||
'connection' => env('SESSION_CONNECTION'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" session driver, you may specify the table we
|
||||
| should use to manage the sessions. Of course, a sensible default is
|
||||
| provided for you; however, you are free to change this as needed.
|
||||
|
|
||||
*/
|
||||
|
||||
'table' => 'sessions',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While using one of the framework's cache driven session backends you may
|
||||
| list a cache store that should be used for these sessions. This value
|
||||
| must match with one of the application's configured cache "stores".
|
||||
|
|
||||
| Affects: "apc", "dynamodb", "memcached", "redis"
|
||||
|
|
||||
*/
|
||||
|
||||
'store' => env('SESSION_STORE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Sweeping Lottery
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Some session drivers must manually sweep their storage location to get
|
||||
| rid of old sessions from storage. Here are the chances that it will
|
||||
| happen on a given request. By default, the odds are 2 out of 100.
|
||||
|
|
||||
*/
|
||||
|
||||
'lottery' => [2, 100],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the name of the cookie used to identify a session
|
||||
| instance by ID. The name specified here will get used every time a
|
||||
| new session cookie is created by the framework for every driver.
|
||||
|
|
||||
*/
|
||||
|
||||
'cookie' => env(
|
||||
'SESSION_COOKIE',
|
||||
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The session cookie path determines the path for which the cookie will
|
||||
| be regarded as available. Typically, this will be the root path of
|
||||
| your application but you are free to change this when necessary.
|
||||
|
|
||||
*/
|
||||
|
||||
'path' => '/',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Domain
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the domain of the cookie used to identify a session
|
||||
| in your application. This will determine which domains the cookie is
|
||||
| available to in your application. A sensible default has been set.
|
||||
|
|
||||
*/
|
||||
|
||||
'domain' => env('SESSION_DOMAIN'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTPS Only Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By setting this option to true, session cookies will only be sent back
|
||||
| to the server if the browser has a HTTPS connection. This will keep
|
||||
| the cookie from being sent to you when it can't be done securely.
|
||||
|
|
||||
*/
|
||||
|
||||
'secure' => env('SESSION_SECURE_COOKIE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTP Access Only
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will prevent JavaScript from accessing the
|
||||
| value of the cookie and the cookie will only be accessible through
|
||||
| the HTTP protocol. You are free to modify this option if needed.
|
||||
|
|
||||
*/
|
||||
|
||||
'http_only' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Same-Site Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines how your cookies behave when cross-site requests
|
||||
| take place, and can be used to mitigate CSRF attacks. By default, we
|
||||
| will set this value to "lax" since this is a secure default value.
|
||||
|
|
||||
| Supported: "lax", "strict", "none", null
|
||||
|
|
||||
*/
|
||||
|
||||
'same_site' => 'lax',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Partitioned Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will tie the cookie to the top-level site for
|
||||
| a cross-site context. Partitioned cookies are accepted by the browser
|
||||
| when flagged "secure" and the Same-Site attribute is set to "none".
|
||||
|
|
||||
*/
|
||||
|
||||
'partitioned' => false,
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| View Storage Paths
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Most templating systems load templates from disk. Here you may specify
|
||||
| an array of paths that should be checked for your views. Of course
|
||||
| the usual Laravel view path has already been registered for you.
|
||||
|
|
||||
*/
|
||||
|
||||
'paths' => [
|
||||
resource_path('views'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Compiled View Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines where all the compiled Blade templates will be
|
||||
| stored for your application. Typically, this is within the storage
|
||||
| directory. However, as usual, you are free to change this value.
|
||||
|
|
||||
*/
|
||||
|
||||
'compiled' => env(
|
||||
'VIEW_COMPILED_PATH',
|
||||
realpath(storage_path('framework/views'))
|
||||
),
|
||||
|
||||
];
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue