Community编程与开发github.com

Laravel Waitlist:从等候名单到发布

将 taldres/laravel-waitlist 的等候名单转化为发布流程:按注册顺序分批邀请用户,允许已邀请的地址注册,向所有同意者发布启动公告,并在名单使命完成后清除。

Laravel Waitlist:从等候名单到发布 是什么?

该技能旨在帮助使用 `taldres/laravel-waitlist` 包的 Laravel 应用实现从等候名单到产品发布的完整流程。它涵盖了按先来后到顺序分批发送邀请、允许被邀请者注册、向所有同意接收通知的用户发送启动公告,以及在名单使命完成后将其彻底清除。技能提供了清晰的步骤:首先在应用模型中自定义记录 `invited_at` 字段;然后通过宏实现批次邀请并发送带退订链接的邮件;接着在注册控制器中验证用户是否已被邀请;之后向所有有效收件人发送启动公告;最后使用 `forgetAll` 方法安全地清除名单。该技能支持多项目隔离,遵循约定优于配置原则,并提供了详尽的示例和反模式说明,帮助开发者避免常见错误,例如从 `entries()` 查询时遗漏 `whereConsentedTo()` 过滤器或发布后永久保留名单。

兼容平台~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 状态;请在此基础上自行构建。

主要目标

  • 仅向当前目标活跃的地址发送邀请和公告,在应用中记录邀请,并在名单完成使命后清除。

工作流程

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 包含一个带有令牌的退订 URL;请让它实现 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() 进行邀请:这会包含未确认的地址和已离开的人员。
  • 发布后永久保留名单“以防万一”。
  • 向包的 status 或 end_reasons 中添加 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.

相关技能