validated('token')); // Try artists table $artist = DB::table('artists')->where('portal_token', $hashedToken)->first(); if ($artist) { $event = Event::withoutGlobalScope(OrganisationScope::class)->find($artist->event_id); return response()->json([ 'context' => 'artist', 'data' => [ 'id' => $artist->id, 'name' => $artist->name, 'booking_status' => $artist->booking_status, ], 'event' => $event ? new PortalEventResource($event) : null, ]); } // Try production_requests table (may not exist yet) try { $productionRequest = DB::table('production_requests')->where('token', $hashedToken)->first(); if ($productionRequest) { $event = Event::withoutGlobalScope(OrganisationScope::class)->find($productionRequest->event_id); return response()->json([ 'context' => 'supplier', 'data' => [ 'id' => $productionRequest->id, 'name' => $productionRequest->name ?? null, ], 'event' => $event ? new PortalEventResource($event) : null, ]); } } catch (\Illuminate\Database\QueryException) { // Table doesn't exist yet — skip } return response()->json([ 'message' => 'Invalid or expired portal token', ], 401); } }