state-comparison_skill

This skill helps you replace verbose state checks with clean helper methods for readable, type-safe state logic in your models.
  • TypeScript

1

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill hackur/web-standards-playground-showcase --skill state-comparison

  • SKILL.md8.7 KB

Overview

This skill provides a set of model helper patterns to replace verbose Spatie Model States comparisons with concise, testable methods and query scopes. It reduces boilerplate, improves readability, and centralizes state logic so changes are made in one place. The result is clearer conditional logic, safer refactors, and about 63% less code for common state checks.

How this skill works

Add generic state-check methods, convenience boolean helpers for each state, and query scopes on models. Helpers like isCardQualityCheck() or isCompleted() call a single isState(state) method, while scopeWhereState and scopeWhereStateIn allow efficient database filtering. Use hasStateIn([...]) for multiple-state checks and specialized helpers like isTerminalState() where appropriate.

When to use it

  • Replace repeated Spatie Model States equals(...) expressions in business logic
  • Write conditional view or controller logic that depends on model state
  • Filter queries by one or more states in repositories or controllers
  • Refactor legacy code to remove magic strings and reduce typos
  • Provide IDE-friendly, discoverable helpers for developer experience

Best practices

  • Implement a single generic check (isXState) and build convenience methods on top
  • Add scopeWhereState and scopeWhereStateIn for database-level filtering
  • Name helpers explicitly (isCardQualityCheck) — avoid ambiguous abbreviations
  • Use hasStateIn([...]) or a terminal-state helper instead of multiple OR checks
  • Write tests that assert helper behavior so refactors remain safe

Example use cases

  • Replace (new ($card->card_state)($card))->equals(...) with $card->isCardQualityCheck() in controllers
  • Use Submission::whereSubmissionStateIn([...])->get() to load submissions in multiple states efficiently
  • Use $submission->isTerminalState() to guard side effects like notifications
  • Render badges in views with @if($submission->isCompleted()) instead of verbose state builds
  • Refactor nested ternaries to a match expression driven by helper methods

FAQ

Yes. Centralizing comparisons in helper methods provides a single source of truth so you update logic in one place and all callers inherit the change.

Do query scopes handle multiple states efficiently?

Yes. scopeWhereStateIn uses whereIn so the database does the filtering and you avoid loading all models then filtering in PHP.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational