Community程式設計與開發github.com

Laravel Waitlist:從等待清單到正式發布

將 taldres/laravel-waitlist 等待清單轉變為正式發布流程:按註冊順序分批邀請、讓受邀者註冊、向所有同意者發布公告,並在目的達成後清除清單。

Laravel Waitlist:從等待清單到正式發布 是什麼?

此技能專為使用 `taldres/laravel-waitlist` 套件的應用程式設計,提供從「等待清單」到「正式發布」的完整流程。它涵蓋了分批邀請(按先進先出順序記錄邀請)、僅讓已邀請且仍維持同意的地址註冊、向所有同意者發布啟動公告,以及最終清除清單等步驟。支援 Laravel 框架,並透過自訂模型擴充(如將狀態寫入 `invited_at` 欄位)來實現。主要程式碼片段包括建立用於批次邀請的巨集(macro)、驗證註冊條件的邏輯、發送大量通知以及使用 `php artisan` 指令安全地清除清單。此技能遵循關鍵規則:從不直接操作套件的訂閱、同意或活動記錄,而是透過自己的模型欄位來管理狀態。

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

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Laravel Waitlist:從等待清單到正式發布 是做什麼的?

當使用 taldres/laravel-waitlist 的應用程式希望讓使用者逐步進入時,使用此技能:早期存取邀請、發布公告,以及後續清理。該套件有意不提供 invited 狀態;請在上層建構此功能。

主要目標

  • 僅向仍處於活躍目的(purpose)的地址發送邀請和公告,在應用程式中記錄邀請,並在清單完成使命後清除。

工作流程

1. 在自訂模型中記錄邀請

// 應用程式的遷移檔
Schema::table('waitlist_entries', function (Blueprint $table) {
    $table->timestamp('invited_at')->nullable();
});
namespace App\Models;

use Taldres\Waitlist\Models\WaitlistEntry as BaseEntry;

class WaitlistEntry extends BaseEntry
{
    public function __construct(array $attributes = [])
    {
        $this->mergeFillable(['invited_at']);   // 在父類別填充模型之前合併

        parent::__construct($attributes);
    }

    protected function casts(): array
    {
        return parent::casts() + ['invited_at' => 'datetime'];
    }
}
// config/waitlist.php
'model' => App\Models\WaitlistEntry::class,

如果子類別覆寫了 booted(),則必須呼叫 parent::booted()。

2. 按先到先服務原則邀請下一批

use Illuminate\Support\Facades\Mail;
use Taldres\Waitlist\Facades\Waitlist;
use Taldres\Waitlist\ScopedWaitlist;

// AppServiceProvider::boot()
ScopedWaitlist::macro('inviteNext', function (int $count = 10) {
    /** @var ScopedWaitlist $this */
    return $this->entries()
        ->whereConsentedTo('waitlist')   // 清單的主要目的:已確認且仍在清單上
        ->whereNull('invited_at')
        ->oldest()
        ->limit($count)
        ->get()
        ->each(function ($entry) {
            $entry->forceFill(['invited_at' => now()])->save();
            Mail::to($entry->email)->queue(new YouAreInMail($entry, Waitlist::unsubscribeUrl($entry)));
        });
});
Waitlist::for('beta')->inviteNext(25);   // 從排程指令、管理員操作或 Tinker 執行

YouAreInMail 應包含一個附帶令牌的取消訂閱連結;讓它實作 ShouldBeEncrypted,以便佇列的郵件能加密儲存。

3. 讓受邀地址進入

$entry = Waitlist::for('beta')->find($request->string('email')->value());

abort_unless($entry?->invited_at !== null && $entry->hasConsentFor('waitlist'), 403);

find() 也會返回已離開的地址;請使用 hasConsentFor() 或狀態進行檢查。

4. 發布啟動公告

use Taldres\Waitlist\Support\Recipient;

Waitlist::for('beta')->recipients()->each(
    fn (Recipient $recipient) => Mail::to($recipient->email)->locale($recipient->locale)->queue(new LaunchMail($recipient)),
);

recipients() 返回所有主要目的處於活躍狀態的地址(每個唯一一次),並附有該清單的取消訂閱連結和一鍵式標頭($recipient->unsubscribeUrl()、$recipient->listUnsubscribeHeaders())。

5. 目的達成後清除清單

當等待清單的目的(例如「早期存取開放時寄信通知我」)達成後,清除它:

php artisan waitlist:forget --list=beta --all     # 若無終端機則會先詢問;加上 --force 可跳過確認

或使用 Waitlist::for('beta')->forgetAll()。它會清除該清單的所有條目及其所有同意,包括選擇性的同意(如電子報)。同意無法轉移:某人只能透過他自行加入的另一個清單(例如以 newsletter 為主要目的 news 清單)保留電子報。請在清除前邀請他加入該清單。

規則、參考與範本

範例

  • 「每週一從 beta 等待清單邀請 50 人」:在排程指令中使用步驟 2 的巨集。
  • 「僅有已加入等待清單的人才能在早期存取期間註冊」:在註冊控制器中使用步驟 3。
  • 「我們已發布,清理等待清單」:先執行步驟 4,再執行步驟 5。

反模式

  • 從 entries() 中邀請時未使用 whereConsentedTo():這會包含未確認的地址以及已離開的人。
  • 發布後「以防萬一」永遠保留清單。
  • 在套件的狀態或結束原因中加入 invited 或 rejected。
  • 在邀請郵件中加入管理連結。

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

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.

相關技能