Community编程与开发github.com

Taldres/laravel-waitlist(多项目管理)

在一个 Laravel 应用中为多个产品管理候补名单。支持定义独立项目、按项目范围调用、处理 HTTP 注册、按项目发送邮件,以及集中查询所有项目数据。

laravel-waitlist(多项目管理) 是什么?

此技能用于在单个 Laravel 应用中同时管理多个产品的候补名单。它通过“项目”(Project)概念将不同产品的候补名单、字段、邮件模板和页面完全隔离,避免数据混淆。开发者可以定义默认项目(面向主产品)和多个命名项目,所有 Facade 调用通过 `project()` 方法限定作用域;HTTP 注册通过可自定义的 `ProjectResolver` 自动解析所属项目,并配合 Laravel Gate 进行权限控制。该技能支持邮件按项目配置、跨项目全局查询(如个人信息删除、报表),以及将项目定义存储在数据库中以支持运行时动态变更。它适用于多产品 SaaS 平台、子品牌候补名单或集中式候补名单 API 场景,但注意项目不提供租户隔离,不适合作为多租户方案使用。主要支持 Taldres/laravel-waitlist 包,工作流包括:定义项目 → 作用域化调用 → 配置 HTTP 解析器 → 设置 Gate 认证 → 按项目发送邮件 → 跨项目全局处理。

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

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

在你喜欢的 AI 中提问

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

文档

Laravel Waitlist:多项目管理

当一个应用要为多个产品收集候补名单,或为已有的 taldres/laravel-waitlist 设置添加第二个产品时使用此技能。如果只有一个产品,则无需以下任何操作:Waitlist::define() 不指定名称时描述的是 default 项目。

主要目标

  • 每次调用、注册和邮件都作用于正确的产品,不会有任何操作静默落入默认项目。

工作流程

1. 定义项目

每个项目都有自己的用途、列表、字段和页面;不会从默认项目或其他项目继承任何内容。列表名只需在项目内唯一。

// app/Providers/WaitlistServiceProvider.php, boot()
use Taldres\Waitlist\Definitions\ProjectDefinition;
use Taldres\Waitlist\Facades\Waitlist;

// 默认项目保持无列表,这样忘记使用 project() 的注册会失败,而非落入错误产品。其页面会捕获未知的 token。
Waitlist::define(fn (ProjectDefinition $project) => $project->urls(
    invalid: 'https://example.com/waitlist/oops',
));

Waitlist::define('rocket', function (ProjectDefinition $project): void {
    $project->purpose('waitlist', ['2026-10' => 'Rocket 发布时请邮件通知我。']);
    $project->list('default', purpose: 'waitlist');
    $project->fields(fn () => ['source' => ['nullable', 'string', 'max:50']]);
    $project->urls(
        confirm: 'https://rocket.example/waitlist/confirm/{token}',
        unsubscribe: 'https://rocket.example/waitlist/leave/{token}',
        manage: 'https://rocket.example/waitlist/preferences/{token}',
    );
});

Waitlist::define('anvil', function (ProjectDefinition $project): void { /* 相同方法 */ });
  • 将主产品保留在默认项目中并命名其他项目也可行;那么每次未使用 project() 的调用都将作用于主产品。
  • 字段按项目和列表划分:$project->fields() 应用于所有列表,列表自身的 ->fields() 会叠加。一个项目的字段永远不会影响到另一个项目;无字段的项目不接受 HTTP 元数据。
  • 通过 config() 读取环境变量,永远不要使用 env()。再次定义项目会替换之前的定义;回调在项目首次被需要时执行。

2. 限定每次调用的作用域

Waitlist::project('rocket')->for('default')->add($email, $purposes);
Waitlist::project('rocket')->purposes('default', app()->getLocale());
Waitlist::project('rocket')->recipients('newsletter');
Waitlist::project('rocket')->report()->since(30)->totals();
  • 不指定 project() 时,Facade 作用于默认项目,而非所有项目。
  • Token 相关方法(Waitlist::confirm()、unsubscribe()、withdrawConsent()、requestManageLink())无需指定项目:因为 token 已属于其记录。
  • 未知项目会抛出 UnknownProjectException。

3. HTTP 注册需要解析器

当 WAITLIST_ROUTES_ENABLED=true 时,注册、措辞以及通过地址请求的管理链接,将作用于 ProjectResolver 返回的项目。默认的 DefaultProjectResolver 总是返回 default,因此需要绑定一个自定义解析器:

namespace App\Waitlist;

use Illuminate\Http\Request;
use Taldres\Waitlist\Contracts\ProjectResolver;

class SiteResolver implements ProjectResolver
{
    public function resolve(Request $request): string
    {
        $host = parse_url((string) $request->headers->get('Origin'), PHP_URL_HOST) ?: $request->getHost();

        return match ($host) {
            'rocket.example' => 'rocket',
            'anvil.example' => 'anvil',
            default => abort(403),
        };
    }
}
// config/waitlist.php
'project_resolver' => App\Waitlist\SiteResolver::class,
  • 未指定 list 的注册会进入解析后项目的 waitlist.default_list(即 default):为每个项目配备一个同名列表,或始终提交 list 参数。
  • 解析器在每个请求中首先运行,随后是 useWaitlist 守卫,两者均在请求体验证之前:项目决定了接受哪些字段,被拒绝的请求会直接返回 401/403 而不读取内容。
  • 来自解析器的未知项目:注册返回 422,措辞返回 404。
  • 自有控制器无需解析器;它们可直接调用 Waitlist::project(...)。
  • 永远不要在 waitlist.routes.middleware 中进行身份认证;它也会守卫 token 链接。

3b. 谁可以调用:useWaitlist 守卫和带凭证的服务器

在注册、措辞和通过地址请求的管理链接(不适用于 token 链接)之前,包会询问 Laravel 的 useWaitlist 守卫,传入 (?Authenticatable $caller, string $project, WaitlistAction $action, ?string $list)。调用者来自 waitlist.authentication.guards 中第一个对请求进行身份认证的守卫;Waitlist::caller($request) 会返回同一个调用者。config/auth.php 中未定义的守卫会被拒绝并报出其名称;token 链接不会等待守卫,并且会被当作访客请求进行限制。

  • 默认情况下:任何人都可以;如果调用者实现了 HasWaitlistProject,则仅限其自有项目(否则返回 404)。当 waitlist.authentication.required 启用时:访客返回 401,无项目的调用者返回 403。
  • 可在任何服务提供者中使用 Gate::define('useWaitlist', ...) 替换该守卫;无论哪个提供者先启动,自定义定义都生效。返回布尔值或守卫响应;Response::denyWithStatus(401) 和 denyAsNotFound() 会传达给客户端。
  • 使用自有 token 调用的服务器:token 的模型需实现 HasWaitlistProject,project_resolver 设为 AuthenticatedProjectResolver(无调用者时返回 401,无项目或项目未定义时返回 403),authentication.guards 指定 token 守卫,authentication.required 开启。token 的签发和撤销由应用负责(Sanctum、Passport、JWT 守卫);同样需要守卫它们,例如在 Sanctum::authenticateAccessTokensUsing() 中使用 Waitlist::hasProject()。
  • Sanctum 的能力通过 tokenCan() 读取,而非 can(),后者会询问守卫和策略。
  • 此类服务器从单一地址为所有访客发送请求:默认限流器会限制每个服务器(rate_limits.caller_signup_per_minute,120),并将每个访客的限制留给自己处理,例如在 Next.js Server Action 中。设置 authentication.client_ip_header(例如 X-Waitlist-Client-Ip)也可限制转发的访客;该头部永远不会从访客读取,非 IP 地址的值会被忽略。
  • $project->wordingFromCallers() 允许它们发送包含版本的同意文本({version, locale?, text}),因此文本仅存在于站点上:首次注册时将其与服务器一同登记;已知版本必须读取相同内容。守卫对此类注册会询问 WaitlistAction::RegisterWording;默认情况下只有代表项目操作的调用者才能获取。

4. 按项目发送邮件

监听器读取 $event->entry->project 并根据项目选择发送者、邮件程序和模板。邮件链接已指向项目自己的页面(urls());未定义 URL 的项目使用包路由,若路由关闭则为 null。

5. 关于某个人的请求覆盖所有项目

Waitlist::allProjects()->personalData($email);
Waitlist::allProjects()->forget($email);
Waitlist::allProjects()->report();

waitlist:show、waitlist:forget、waitlist:prune 和 waitlist:privacy 默认覆盖所有项目(除非指定 --project),而 --list 会将范围缩小为默认项目的该列表;waitlist:export、waitlist:wording 和 waitlist:forget --all 作用于默认项目,除非指定了 --project。

6. 数据库中的项目

对于运行时动态变化、或需要管理自身列表和措辞的项目,可以绑定一个 ProjectCatalog(waitlist.catalog),通常继承 StoredWordingCatalog,并实现 policy()、fields()(字段 => 规则;存储的规则只能是字符串)、urlPattern()、projects()(必须包含 default)和 lists(),以及一个将可发布键映射到项目的解析器。自定义的 catalog 会替换定义。项目通过 Waitlist::project($key)->registerWording() 注册措辞。

规则、参考与模板

示例

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

Build the pages of a taldres/laravel-waitlist integration: the signup form with the registered wording, and the confirm, unsubscribe and preference pages, either in Laravel controllers (Blade, Livewire, Inertia) or in an SPA or static site over the package's JSON API, including CORS and bot protection.

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

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.

相关技能