Playa: Cookie-Based Temporary Players for Laravel

最后更新于 经过

Playa: Cookie-Based Temporary Players for Laravel image

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

添加 playa middleware to any route where you want a player resolved or created:

路线 :: 得到 '/join/{game}' , JoinGameController ::班级
-> 中间件 ([ '网络' , 'playa' ])
-> 姓名 '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 = $请求 -> player ();
使用 CharlieLangridge\Playa\Facades\Playa ;
$player = Playa :: player ();
$player = Playa :: findByUuid ($uuid);
Playa :: 忘记 ();

The model includes nameusername 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 授權 () -> 用户 ());
$player -> unlinkUser ();

The package supports bigint , uuid , ulid , 和 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:

  • PlayerCreated
  • PlayerResolved
  • PlayerRenewed
  • PlayerExpired
  • PlayerLinkedToUser

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 工匠 playa:prune
php 工匠 playa:prune --hours=24

Playa requires PHP 8.4 and supports Laravel 11, 12, and 13.

To learn more, view the source on GitHub

保罗·雷德蒙德照片

Laravel News 特约撰稿人。全栈 Web 开发人员兼作家。

归档于:
立方体

Laravel 时事通讯

加入超过 4 万名开发者的行列,不错过任何新的技巧、教程等内容。

图像
SerpApi

适用于您的 LLM 和 AI 应用的 Web 搜索 API

访问 SerpApi
Laravel Cloud 标志

Laravel 云

轻松创建和管理服务器,并在几秒钟内部署 Laravel 应用程序。

Laravel 云
绝不妥协标志

绝不妥协

来自 No Compromises 播客的两位经验丰富的开发者 Joel 和 Aaron 现在可以为您的 Laravel 项目提供服务。⬧ 固定费用 9500 美元/月。⬧ 无冗长的销售流程。⬧ 无需签订合同。⬧ 100% 退款保证。

绝不妥协
Lucky Media 标志

幸运传媒

Get Lucky Now——拥有十余年经验的 Laravel 开发理想之选!

幸运传媒
Shift 标志

转移

还在运行旧版本的 Laravel?立即实现 Laravel 自动升级和代码现代化,让您的应用程序保持最新状态。

转移
PhpStorm 标志

PhpStorm

首选的 PHP IDE,对 Laravel 及其生态系统提供广泛的开箱即用支持。

PhpStorm
Kirschbaum 标志

樱桃树

提供创新和稳定性,确保您的Web应用程序取得成功。

樱桃树
鱼叉:新一代时间跟踪和发票标志

Harpoon:新一代时间跟踪和发票系统

新一代时间跟踪和计费软件,帮助您的机构规划和预测盈利的未来。

Harpoon:新一代时间跟踪和发票系统
了解 Softtech 的标志

了解软科技

Acquaint Softtech 提供 AI 就绪的 Laravel 开发人员,48 小时内即可上手,每月费用为 3000 美元,没有冗长的销售流程,并提供 100% 退款保证。

了解软科技
Tinkerwell 徽标

廷克威尔

Laravel 开发者必备的代码运行器。可在本地和生产环境中体验 AI、自动补全和即时反馈功能。

廷克威尔
SaaSykit:Laravel SaaS 入门套件徽标

SaaSykit:Laravel SaaS 入门套件

SaaSykit 是一个多租户 Laravel SaaS 入门套件,包含运行现代 SaaS 所需的所有功能,例如支付、美观的结账界面、管理面板、用户仪表盘、身份验证、现成组件、统计数据、博客、文档等等。

SaaSykit:Laravel SaaS 入门套件
Laracon AU 2026 Announces Full Speaker Lineup, Schedule, and Workshops image

Laracon AU 2026 Announces Full Speaker Lineup, Schedule, and Workshops

阅读文章
Parsel: Parse PDFs, Office Documents, and Images in PHP image

Parsel: Parse PDFs, Office Documents, and Images in PHP

阅读文章
Typed Objects for Eloquent with Expressive image

Typed Objects for Eloquent with Expressive

阅读文章
Malware Blocking and Dependency Policies in Composer 2.10 image

Malware Blocking and Dependency Policies in Composer 2.10

阅读文章
Aegis for Laravel: Scaffolding and Validation Helpers for Value Objects image

Aegis for Laravel: Scaffolding and Validation Helpers for Value Objects

阅读文章
Scheduler Attributes and Listener Discovery Control in Laravel 13.12.0 image

Scheduler Attributes and Listener Discovery Control in Laravel 13.12.0

阅读文章