Community程式設計與開發github.com

Taldres/laravel-waitlist

在單一 Laravel 應用程式中管理多個產品的等候清單,支援專案定義、範圍限定、HTTP 註冊解析、每專案郵件發送、跨專案請求處理,以及資料庫驅動的中央等候清單 API。

laravel-waitlist 是什麼?

此技能專為需要管理多個產品等候清單的 Laravel 應用程式設計。透過 `taldres/laravel-waitlist` 套件,開發者可以將不同產品定義為獨立專案,每個專案擁有專屬的等候清單、欄位、頁面與郵件設定,避免資料混淆。 它支援透過 `project()` 方法進行呼叫範圍限定,確保所有操作(如新增註冊、查詢人數、寄送郵件)都對應到正確的產品。此外,也提供 HTTP 路由與 `ProjectResolver` 機制,讓不同網域或來源的註冊請求自動路由至對應專案。 對於需集中控管多個動態專案的場景,可以使用資料庫驅動的 `ProjectCatalog` 實作,讓專案、其清單與同意文字能夠在執行時動態增減。此技能適用於 Claude Code、Cursor 等 AI 編碼代理,協助開發者快速理解並實作多產品等候清單的需求。

相容平台~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' => '火箭發射時請通知我。']);
    $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 gate,兩者都在請求主體驗證之前執行:專案決定接受哪些欄位,被拒絕的請求會以 401/403 回應。
  • 解析器回傳未知專案:註冊回 422,同意文字回 404。
  • 自訂控制器不需要解析器;它們可以直接呼叫 Waitlist::project(...)。
  • 請勿在 waitlist.routes.middleware 中進行驗證;它同時也會保護 token 連結。

3b. 誰可以呼叫:useWaitlist gate 與使用憑證的伺服器

套件會在註冊、同意文字及透過地址請求的管理連結之前(但 token 連結永遠不會),檢查 Laravel 的 useWaitlist gate,傳遞 (?Authenticatable $caller, string $project, WaitlistAction $action, ?string $list)。呼叫者來自 waitlist.authentication.guards 中第一個成功驗證請求的 guard;Waitlist::caller($request) 會回傳同一個呼叫者。若 config/auth.php 未定義某個 guard,則會拒絕並指出該 guard 名稱;token 連結不會等待 guard,並會以訪客身分限制請求。

  • 預設:所有人都可以呼叫;實作 HasWaitlistProject 的呼叫者僅能存取自己的專案(否則回 404)。啟用 waitlist.authentication.required 後:訪客收到 401,沒有專案的呼叫者收到 403。
  • 可在任何 Service Provider 中使用 Gate::define('useWaitlist', ...) 覆寫;先啟動的 provider 優先。回傳 bool 或 gate response;Response::denyWithStatus(401) 與 denyAsNotFound() 會反映至客戶端。
  • 使用自有 token 的伺服器:token 的模型實作 HasWaitlistProject,project_resolver 設為 AuthenticatedProjectResolver(無呼叫者時回 401,無專案或未知專案時回 403),authentication.guards 指定 token guard,並啟用 authentication.required。token 的發行與撤銷由應用程式負責(Sanctum、Passport 或 JWT guard);也應對其進行 gate 控制,例如使用 Sanctum::authenticateAccessTokensUsing() 搭配 Waitlist::hasProject()。
  • Sanctum abilities 應使用 tokenCan() 讀取,而非 can()(後者會詢問 gates 與 policies)。
  • 此類伺服器會從單一地址為所有訪客發送請求:預設限流器會限制每個伺服器(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}),使其僅存在於網站上:第一次註冊時會將該文字註冊到伺服器;已知版本必須讀取相同文字。此類註冊的 gate 會詢問 WaitlistAction::RegisterWording;預設只有作用於該專案的呼叫者才能取得。

4. 每個專案的郵件

監聽器讀取 $event->entry->project,並據此選擇寄件者、郵件驅動程式與範本。郵件連結已指向專案自己的頁面(urls());沒有頁面的專案會使用套件路由,或是在路由關閉時設為 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(),再加上一個能將可發布的 key 映射到專案的解析器。自訂的 catalog 會取代定義。專案可使用 Waitlist::project($key)->registerWording() 註冊同意文字。

規則、參考與範本

範例

  • 「為我們的第二個產品新增等候清單」:將第一個產品保留在預設專案或也為其命名,為第二個產品新增 Waitlist::define('<key>', ...),使用 project() 限定其呼叫範圍,若註冊源自 HTTP 則綁定一個解析器。
  • 「刪除 [email protected] 的所有資料」:Waitlist::allProjects()->forget('[email protected]')。

反模式

  • 啟用套件路由但未設定解析器:所有 HTTP 註冊都會進入 default 專案。
  • 依賴預設 gate 來關閉 API:若未啟用 waitlist.authentication.required 或未使用 AuthenticatedProjectResolver,未提供 token 的呼叫者會是訪客,而訪客可以存取。
  • 對一個已有專屬專案的產品使用 Waitlist::for($list)。
  • 預期專案會繼承預設專案的用途、清單、欄位或頁面。
  • 當使用者存在於多個產品時,使用 Waitlist::project($key)->forget() 回應其刪除請求。

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.

相關技能