Community编程与开发github.com

Taldres/laravel-waitlist 前端页面

构建 taldres/laravel-waitlist 集成的前端页面:包含带有注册文案的注册表单、确认页、取消订阅页和偏好设置页,支持 Laravel 控制器(Blade、Livewire、Inertia)或通过包的 JSON API 构建 SPA/静态站点,并包含 CORS 和机器人保护。

laravel-waitlist 前端页面 是什么?

该技能指导开发者如何为 `taldres/laravel-waitlist` Laravel 包构建完整的前端页面集。它涵盖了注册表单、确认页面、取消订阅页面和偏好设置页面的实现,支持两种架构方式:使用 Blade、Livewire、Inertia 等 Laravel 控制器渲染页面,或者通过启用 `WAITLIST_ROUTES_ENABLED=true` 并调用 JSON API 来构建 SPA 或无后端的静态站点。该技能强调了关键规则:表单必须显示从包中获取的注册文案,并原样提交;链接背后的页面绝不能在 GET 请求上改变状态(防止邮件扫描器误触)。还提供了详细的代码示例,包括验证、错误处理、CORS 配置、机器人保护(如 Cloudflare Turnstile)以及反模式指南(如不在 GET 上确认/退订、硬编码文案、区分新旧地址等),适用于 Claude Code、Cursor 或 Codex 等 AI 编码代理。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Taldres/laravel-waitlist/tree/HEAD/resources/boost/skills/laravel-waitlist-frontend

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Laravel Waitlist:前端页面

在构建或修改 taldres/laravel-waitlist 的注册表单、确认页面、取消订阅页面或偏好设置页面时使用此技能。

主要目标

  • 表单必须准确显示包的注册文案,并提交所显示的内容;邮件链接后面的页面绝不能在 GET 请求上改变状态。

工作流程

1. 选择架构

  • Laravel 渲染页面(Blade、Livewire、Inertia):在控制器中调用 Waitlist 门面。包的预定义路由可以保持关闭,除非邮件需要携带 RFC 8058 一键 List-Unsubscribe 标头(这需要启用路由);无论采用哪种方式,页面都会渲染 UI。
  • SPA 或静态站点(无 Laravel 后端用于页面渲染):设置 WAITLIST_ROUTES_ENABLED=true 并调用 /waitlist 下的 JSON API。

无论采用哪种方式,都需要在项目的定义文件(app/Providers/WaitlistServiceProvider.php)中将邮件链接指向应用自己的页面。通过 config() 读取环境变量,绝不能使用 env():

$project->urls(
    confirm: config('app.frontend_url').'/waitlist/confirm/{token}',
    unsubscribe: config('app.frontend_url').'/waitlist/leave/{token}',
    manage: config('app.frontend_url').'/waitlist/preferences/{token}',
);

同样的调用也接受 confirmed、expired、invalid、unsubscribed 和 erased 参数,这些是浏览器在向包路由提交表单后跳转到的页面。

2. 注册表单

从包中渲染文案,切勿在模板中硬编码:

return view('waitlist.signup', [
    'purposes' => Waitlist::purposes('default', locale: app()->getLocale()),
]);
@foreach ($purposes as $wording)
    <input type="hidden" name="purposes[{{ $wording->purpose }}][version]" value="{{ $wording->version }}">
    <input type="hidden" name="purposes[{{ $wording->purpose }}][locale]" value="{{ $wording->locale }}">
    <input type="hidden" name="purposes[{{ $wording->purpose }}][hash]" value="{{ $wording->hash() }}">

    @if ($wording->required)
        <input type="hidden" name="agreed[]" value="{{ $wording->purpose }}">
        <p>{{ $wording->text }}</p>
    @else
        <label><input type="checkbox" name="agreed[]" value="{{ $wording->purpose }}"> {{ $wording->text }}</label>
    @endif
@endforeach
use Illuminate\Support\Arr;
use Taldres\Waitlist\Exceptions\WaitlistException;
use Taldres\Waitlist\Http\Rules\PurposeChoice;
use Taldres\Waitlist\Support\RequestContext;

$validated = $request->validate([
    'email' => ['required', 'email:filter', 'max:255'],
    'purposes' => ['required', 'array'],
    'purposes.*' => ['required', new PurposeChoice],
    'agreed' => ['required', 'array'],
    'agreed.*' => ['string'],
]);

try {
    Waitlist::for('default')->add($validated['email'], Arr::only($validated['purposes'], $validated['agreed']), context: RequestContext::fromRequest($request));
} catch (WaitlistException $exception) {
    return back()->withErrors(['purposes' => $exception->getMessage()]);
}

return view('waitlist.check-your-inbox'); // 对新的和已知地址返回相同的响应

通过 HTTP:GET /waitlist/purposes?list=default&locale=de,然后 POST /waitlist,携带 email、list 和 purposes(格式为 {purpose: {version, locale, hash}})。回传响应中提供的 locale(可能是一种回退语言)。响应:对所有地址返回 202,422 表示字段验证失败。

如果从你自己的服务器调用(例如 Next.js Server Actions,或带项目令牌的 BFF):将令牌保留在服务器端,并在此限制每个访问者,因为 API 只能看到你的服务器。使用项目的 wordingFromCallers(),服务器可以提交 {version, locale?, text},其中包含表单显示的确切文本,而不必从 API 渲染文案。

除地址外的更多信息放在 metadata 中,并且只能是项目或列表定义的字段($project->fields(...),或列表上的 ->fields(...));其他任何字段都会导致 422。在你自己的控制器中,使用 Waitlist::for('default')->fields() 进行验证。

3. 确认页面

邮件链接打开页面;页面将令牌回传给服务器。

use Taldres\Waitlist\Exceptions\ExpiredTokenException;
use Taldres\Waitlist\Exceptions\InvalidTokenException;

try {
    Waitlist::confirm($token);
} catch (ExpiredTokenException) {
    return view('waitlist.expired');
} catch (InvalidTokenException) {
    abort(404);
}

通过 HTTP:POST /waitlist/confirm/{token} 并携带 Accept: application/json 响应为 {"data": {..., "status": "confirmed"}},未知令牌返回 404,过期返回 410;包的拒绝响应会命名一个 error,例如 invalid_token,而一个没有 error 的 404 意味着错误的 URL、路由已关闭,或者 useWaitlist 看门机制阻止了调用者。

4. 取消订阅页面

// 来自页面的 POST;针对单个目的的链接携带 ?purpose=
$purpose = $request->query('purpose');

is_string($purpose)
    ? Waitlist::withdrawConsent($token, $purpose)   // 仅撤销该目的
    : Waitlist::unsubscribe($token);                // 退出列表

Waitlist::requestManageLink($token);                // "改为管理偏好设置":发送管理链接邮件

两者都会对未知令牌抛出 InvalidTokenException。

通过 HTTP:POST /waitlist/unsubscribe/{token}[?purpose=] 和 POST /waitlist/manage-link,携带 {"token": ...}。

5. 偏好设置页面

通过邮件链接中的管理令牌访问(有效期由 waitlist.manage.token_ttl 配置,默认 60 分钟,至少 1 分钟,绝不能无限制): GET /waitlist/manage/{token}(返回状态和生效的目的), PUT .../purposes(携带完整所需的目的集合,主要目的必须保留), POST .../data(JSON 格式复制), POST .../unsubscribe, POST .../erase(携带 {"confirm": true})。 当收到 410 时,提供发送新链接的选项。擦除前需请求明确确认。 在 PHP 中:Waitlist::findByManageToken($token), Waitlist::grantConsent($token, $purpose, $version, $locale)。

将 PUT 请求中的 purposes 格式化为与注册表单相同。 启用 WAITLIST_REQUIRE_WORDING_HASH=true 时,仅添加目的时需要其 hash;保留或移除目的则不需要。

6. 保护公共端点

  • 对注册和管理链接按地址进行机器人检查,例如 Cloudflare Turnstile:

    Waitlist::verifySpamUsing(fn (Request $request): bool => Http::asForm()
        ->post('https://challenges.cloudflare.com/turnstile/v0/siteverify', [
            'secret' => config('services.turnstile.secret'),
            'response' => (string) $request->input('turnstile_token'),
            'remoteip' => $request->ip(),
        ])->json('success') === true);
    

    它仅保护包的路由;在自定义控制器中,你需要自己检查。

  • 前端位于其他源:将 'waitlist', 'waitlist/*' 添加到 config/cors.php 的 paths 数组中。

  • 位于代理或 CDN 之后:配置受信任的代理,否则所有访问者将共享同一个速率限制桶。

  • 关闭的路由(默认状态)在任何速率限制或会话启动之前返回 404。如果路由不支持某种方法,Laravel 仍会返回 405,并且会在任何中间件运行之前,通过 OPTIONS 请求返回允许的方法;这两个行为都不会被阻止。空的 WAITLIST_ROUTES_ENABLED= 是配置错误;false 会关闭路由。包将其检查中间件 CheckRouteConfig 置于 Laravel 中间件优先级队列的头部。如果应用后来替换了该列表(例如在包加载后的提供者中调用 setMiddlewarePriority(),或在 booted() 方法中),必须将 Taldres\Waitlist\Http\Middleware\CheckRouteConfig 列在首位;在 bootstrap/app.php 中使用 priority() 则无需额外操作。

规则、参考和模板

示例

  • "在 Blade 着陆页添加一个等待名单表单":步骤 2 到 4,在控制器中实现。
  • "我们的 Nuxt 站点需要等待名单功能":设置 WAITLIST_ROUTES_ENABLED=true,配置 CORS,然后执行步骤 2 到 5 的 HTTP 变体。
  • "为等待名单表单添加 Turnstile 保护":步骤 6,并在表单中随附 turnstile_token。

反模式

  • 在 GET 请求上执行确认或取消订阅;邮件扫描器会跟踪每一个链接。
  • 在模板中硬编码同意文本,或提交文本而不是版本信息。
  • 在响应中区分新地址和已知地址。
  • 在 waitlist.routes.middleware 中添加身份验证:它也会保护令牌链接和一键取消订阅功能。对于封闭式注册,请使用 ProjectResolver 或自定义控制器;对于仅对表单进行检查(例如 CSRF 或源检查),使用 waitlist.routes.group_middleware.signup。
  • 为可选目的提供预勾选的复选框,或一个复选框对应两个目的。

Individual skills in this repo

This repo contains 13 individual skills — each has its own dedicated page.

Taldres/laravel-waitlist

Use this skill when reviewing Laravel package compatibility across composer constraints, PHP versions, Laravel versions, Testbench versions, dependency stability lanes, Windows CI, or matrix-sensitive code and workflow changes.

Taldres/laravel-waitlist

Use this skill when creating or updating the bundled Laravel Boost skill under resources/boost/skills from the package implementation and package documentation. Trigger after public APIs, commands, config, routes, views, publish tags, README content, or examples change.

Taldres/laravel-waitlist

Use this skill when preparing Laravel package releases: CHANGELOG.md updates, generated release notes, GitHub release workflows, version checks, tags, release validation, or release automation changes. Never publish autonomously.

Taldres/laravel-waitlist

Use this skill when adding Laravel package capabilities or wiring them through the service provider: commands, migrations, routes, config merges, views, translations, assets, middleware, publish tags, workbench files, or console-only behavior.

Taldres/laravel-waitlist

Use this skill when writing, editing, fixing, or reviewing package tests with Pest 4/5 and Orchestra Testbench, including TDD, feature tests, unit tests, type coverage, arch tests, workbench behavior, commands, routes, config, migrations, and publishable resources.

Taldres/laravel-waitlist

Integrate taldres/laravel-waitlist in a Laravel application: define purposes, lists and fields, build the signup form, send the confirmation mail from events, add a preference page, and keep consent, retention and encryption intact.

Taldres/laravel-waitlist

Turn a taldres/laravel-waitlist waitlist into a launch: invite people in batches in signup order, let invited addresses register, announce the launch to everyone who agreed, and erase the list once its purpose is fulfilled.

Taldres/laravel-waitlist

Send the mails of a taldres/laravel-waitlist integration: the double opt-in confirmation, the preference page link, a welcome mail, launch mails and newsletters to the people who agreed, with the right unsubscribe links, one-click headers and a sender per project.

Taldres/laravel-waitlist

Operate a taldres/laravel-waitlist installation: answer access and erasure requests, withdraw a purpose on request, apply retention, erase a list once its purpose is fulfilled, rotate APP_KEY with waitlist:rekey, export a list, and check the setup before going live.

Taldres/laravel-waitlist

Run the waitlists of several products in one Laravel app with taldres/laravel-waitlist projects: define projects, scope facade calls with project(), resolve the project of HTTP signups, send mail per project, handle requests across all projects, or keep projects in a database for a central waitlist API.

Taldres/laravel-waitlist

Keep a newsletter tool such as Brevo, Mailchimp or Mailcoach in step with a taldres/laravel-waitlist waitlist: add confirmed contacts per purpose, remove them on withdrawal and erasure, and carry unsubscribes made at the provider back into the waitlist via a webhook.

Taldres/laravel-waitlist

Build waitlist statistics with taldres/laravel-waitlist: signups and confirmations per day for charts, totals and confirmation rates for a period, the confirmed count on any past day, and how many people are on a list right now, for dashboards, admin pages and API endpoints.

Taldres/laravel-waitlist

Write feature tests for an application's taldres/laravel-waitlist integration: get the plain tokens from events, assert the confirmation and other mails, test the signup, confirm and unsubscribe flows in PHP and over the package's HTTP routes, and bypass rate limits and bot checks in tests.

相关技能