Playa gives a Laravel app a lightweight Player model for visitors who aren't logged in. It's aimed at QR-code journeys, event games, voting screens, kiosk flows, and demos where you need to recognize a returning device without putting users through registration.
Tracking Players via Middleware
Add the playa middleware to any route where you want a player resolved or created:
Route::get('/join/{game}', JoinGameController::class) ->middleware(['web', 'playa']) ->name('games.join');
On the first visit the middleware creates a player record and sets the cookie. On subsequent requests it resolves the existing player and, by default, refreshes the expiry timestamp.
Accessing the Current Player
Playa exposes the resolved player through both the request and a facade:
$player = $request->player(); use CharlieLangridge\Playa\Facades\Playa; $player = Playa::player();$player = Playa::findByUuid($uuid);Playa::forget();
The model includes name and username columns plus a JSON data column for any application-specific details you want to attach — score, answers, position in a flow, and so on.
Linking to Authenticated Users
A player can be associated with a real user account without forcing the visitor to log in first. This is useful when someone starts a flow anonymously and later authenticates:
$player->linkUser(auth()->user());$player->unlinkUser();
The package supports bigint, uuid, ulid, and string user key types via the user_id_type config option, and auto_link_authenticated_user will attach the current user automatically when set to true.
Lifecycle Events
Playa dispatches events at each stage so you can hook into player activity without modifying the middleware:
PlayerCreatedPlayerResolvedPlayerRenewedPlayerExpiredPlayerLinkedToUser
These are handy for analytics, audit trails, or triggering follow-up jobs when a device returns.
Expiry and Pruning
Players have a configurable lifetime (default 30 days) and can renew on each visit. Expired records aren't deleted automatically — run the artisan command to clean them up, optionally with a grace period:
php artisan playa:prunephp artisan playa:prune --hours=24
Playa requires PHP 8.4 and supports Laravel 11, 12, and 13.
To learn more, view the source on GitHub.