feat(api): add portal_events to auth/me endpoint

Add persons() relationship to User model and include portal_events
array in MeResource response, mapping each person record to its
event and organisation data for the portal frontend.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 07:38:59 +02:00
parent 34eb790b3e
commit 7228ad9f5a
4 changed files with 187 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Http\Resources\Api\V1;
use App\Models\Person;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
@@ -31,6 +32,18 @@ final class MeResource extends JsonResource
),
'app_roles' => $this->getRoleNames()->values()->all(),
'permissions' => $this->getAllPermissions()->pluck('name')->values()->all(),
'portal_events' => $this->whenLoaded('persons', fn () =>
$this->persons->map(fn (Person $person) => [
'event_id' => $person->event_id,
'event_name' => $person->event->name,
'event_slug' => $person->event->slug,
'organisation_name' => $person->event->organisation->name,
'person_id' => $person->id,
'person_status' => $person->status,
'start_date' => $person->event->start_date?->toDateString(),
'end_date' => $person->event->end_date?->toDateString(),
])
),
];
}
}