spatie/laravel-model-flags
Add lightweight “flags” to Eloquent models via a trait—store process state without extra columns. Check, set, and clear flags, and query with flagged/notFlagged scopes. Ideal for idempotent, restartable jobs like one-time emails or migrations.
lastFlaggedAt() for compliance or debugging.flagged(), notFlagged()) to segment models for analytics or targeted actions.flag('sent_promo')).notFlagged('processed')).flag('admin_access_granted')).Adopt if:
Look elsewhere if:
flag('premium', 'gold')) → Use a JSON column or a separate flag_values table.flags_json column) or caching layers.flag_expiry table.For Executives: "This package lets us turn on/off features or track state for individual records without writing migrations—saving dev time and reducing risk. For example, we can ensure a batch email job only runs once per user, even if it crashes mid-execution. It’s like a lightweight ‘feature flag’ system built into our models, with zero infrastructure changes. Used by teams at [companies using Spatie], it’s battle-tested and MIT-licensed."
For Engineers: *"Pros:
use HasFlags).Model::flagged('x')->get() make filtering trivial.lastFlaggedAt() for auditing.Cons:
Example Use Case:
// In a cron job to send welcome emails:
User::notFlagged('welcome_email_sent')
->each(fn(User $user) => [
Mail::to($user)->send(new WelcomeEmail()),
$user->flag('welcome_email_sent')
]);
Result: Users get emails exactly once, no matter how many times the job runs."*
For PMs: *"This reduces friction for time-sensitive features like:
lastFlaggedAt()).How can I help you explore Laravel packages today?