# AGENTS.md: Livewire components

## Commands
`php artisan make:livewire Orders/Index` · `php artisan test` · `./vendor/bin/pint`
- Check `composer.json` for the Livewire major version and follow its docs (v3 vs v4 differ in file layout).

## Component rules
- Public properties are sent to the browser and can be changed by the user. Never store secrets or trust them: lock ids with `#[Locked]`, and re-authorize in every action (`$this->authorize('update', $this->order)`).
- Validate with `#[Validate('required|email')]` on properties or a Form object (`Livewire\Form`), and call `$this->validate()` in actions.
- Derived data via `#[Computed]` methods (cached per request) instead of storing large collections in public properties.
- Pass models as properties (they're dehydrated to ids) instead of arrays of data.
- Inputs: `wire:model` (deferred) by default; `.live` with `.debounce.300ms` only for search-as-you-type.
- Loops use `wire:key` with a stable id on each item.
- Loading states with `wire:loading` and `wire:target`; disable buttons during submits.
- Small client interactions with Alpine (`x-data`, `$wire`) instead of extra round trips.
- Pagination with `WithPagination`; reset the page when filters change.
- Events between components with `$this->dispatch('order-saved')` and `#[On('order-saved')]`.

## Tests
`Livewire::test(Index::class)->set('search', 'x')->assertSee(...)`, plus authorization tests for every action.
