Community程式設計與開發github.com

Taldres/laravel-waitlist

建構 taldres/laravel-waitlist 整合的頁面:註冊表單及其既定文字,以及確認、取消訂閱和偏好頁面,可使用 Laravel 控制器(Blade、Livewire、Inertia)或透過套件的 JSON API 在 SPA 或靜態網站中實作,包含 CORS 和機器人防護。

laravel-waitlist 是什麼?

此技能專注於為 `taldres/laravel-waitlist` 套件建構前端頁面,涵蓋註冊表單、確認頁面、取消訂閱頁面與偏好頁面。其主要目標是確保表單顯示套件中已註冊的同意文字,並在送出時回傳相同的內容,同時所有透過郵件連結進入的頁面在執行 GET 請求時絕不變更狀態。此技能支援多種架構選擇:可使用 Laravel 的 Blade、Livewire 或 Inertia 直接渲染頁面,亦可設定環境變數 `WAITLIST_ROUTES_ENABLED=true` 啟用 JSON API,讓 SPA(如 Nuxt)或靜態網站透過 HTTP 請求進行整合。工作流程詳細說明如何正確渲染同意文字(包括必填與選填目的)、處理郵件連結中的確認與取消訂閱權杖、透過管理權杖管理偏好設定,以及使用 Cloudflare Turnstile 等方案保護公開端點。此外,技能也明確指出常見的反模式,例如在 GET 請求上執行確認或取消訂閱、直接在模板中鍵入同意文字、區分新舊郵件地址的回應,以及將認證中間件錯誤地應用於所有路由等。

相容平台~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 Facade。套件的路由可以保持關閉,除非郵件需要攜帶 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 渲染。

除了 email 之外的資料應放在 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);
    

    這僅保護套件的路由;在你自己的控制器中,請自行檢查。

  • 前端來自其他來源:在 config/cors.php 的 paths 中加入 'waitlist', 'waitlist/*'。

  • 後端有代理或 CDN:設定受信任的代理,否則所有訪客將共享同一個速率限制桶。

  • 關閉的路由(預設行為)在任何速率限制或 Session 開始前就會回應 404。Laravel 仍會在路由不接受的 HTTP 方法時回應 405,並在執行任何中介軟體前,對 OPTIONS 請求回應允許的方法;這兩種情況都不會執行任何操作。空的 WAITLIST_ROUTES_ENABLED= 屬於設定錯誤;false 則會關閉路由。套件會將自己的 CheckRouteConfig 檢查放在 Laravel 中介軟體優先級清單的開頭。如果應用程式之後(在套件之後啟動的 Provider 中,或在 booted() 中)使用 setMiddlewarePriority() 取代了該清單,則必須將 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 或自己的控制器,並使用 waitlist.routes.group_middleware.signup 對表單進行檢查(例如 CSRF 或來源檢查)。
  • 為選填目的提供預先勾選的核取方塊,或使用單一核取方塊代表兩個目的。

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.

相關技能