livewire

A set of coding rules for Livewire, a Laravel tool for building interactive web interfaces with PHP and templates.

In plain words
What is it for?
Use it when creating or reviewing Livewire components, validation, lifecycle methods, dependency setup, and the separation between PHP classes and Blade templates.
Why use it?
It keeps interface components organized and prevents them from becoming difficult-to-maintain containers for business logic and database work.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/pekral/cursor-rules/livewire
Clone the repo
git clone --depth 1 https://github.com/pekral/cursor-rules
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,459 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02459
Opus 5 $0.00000 $0.01229
Sonnet 5 $0.00000 $0.00492
Haiku 4.5 $0.00000 $0.00246

Measured yesterday against content hash b0175c6f3e7d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

livewire scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/laravel/livewire.mdc · 92 lines

How it starts

The opening of the file, as written. The whole thing — 92 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Component Structure

  • Never use single-file Volt components unless the repository explicitly uses them already.
  • Every Livewire component must be split into:
    • a PHP class in app/Livewire
    • a Blade view in resources/views/livewire
  • Component classes must extend Livewire\\Component.

Responsibilities

  • Livewire components are entry points.
  • Keep component classes slim: accept input, validate, delegate work, update UI state.
  • Do not place business logic directly in Livewire components.
  • Delegate business logic to Actions or Services according to project architecture.
  • Do not execute direct Eloquent queries or DB:: calls in components unless the repository already uses that pattern consistently.

Dependency Injection

  • Livewire does not support constructor injection — it creates components without DI.
  • Use the boot() lifecycle hook to inject service dependencies.
  • Never pass service dependencies as method parameters.

Validation and UI

  • Use Livewire's built-in validation where appropriate.
  • Reuse validation traits from App\\Concerns when available.
  • Keep lifecycle hooks (mount, updated*, dehydrate) slim.
  • Keep Blade templates presentation-only.
  • Prefer Livewire events/listeners over tight component coupling.
  • Use wire:model for form bindings unless there is a clear reason not to.
  • Keep UI strings in the language expected by the repository.

HTML / Blade Layout Splitting

Every Livewire/Blade view must be analyzed as a tree of UI concerns and split into the smallest set of reusable components that still makes the view readable. The goal is reusability and single-responsibility per view file — not maximum component count.

Component-type decision (Livewire vs Blade)

Before extracting anything, pick the right component type. Picking wrong is a code-review finding on its own:

  • Livewire component (app/Livewire/... + resources/views/livewire/...) — extract only when the piece of UI has its own state, lifecycle, or server interaction: holds wire:model form state independent of the parent, owns mount() data loading, exposes wire:click / wire:submit handlers that must hit the server, emits or listens to Livewire events, or carries #[Computed] / updated* lifecycle behavior.
  • Blade component (resources/views/components/... or x-... anonymous) — extract whenever the piece is stateless presentation (data in via attributes / slots, no server round-trip, no Livewire lifecycle). Buttons, cards, badges, headings, layout shells, empty-state messages, icon wrappers, and dumb table rows belong here.
  • Never wrap a stateless presentational block in a Livewire component just to enable reuse — the Livewire wrapper adds a payload, a roundtrip, and a lifecycle the block does not need. Use a Blade component instead. The "split into Livewire components" mandate in this section means split into the correct component type; Livewire components are reserved for the stateful subset above.

Read the full file on GitHub · 92 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 92 lines · 0 tokens per session scan A b0175c6f3e7d

Subscribe to this mod's changes

livewire is a cursor rule published in the GitHub repository pekral/cursor-rules (6 stars, last pushed 7d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,459 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.