# Livewire 4.x Cheatsheet

## Component Definition (SFC)
Filenames use the `⚡` prefix: `resources/views/pages/admin/⚡dashboard.blade.php`.

### Class-based SFC (Recommended)
```php
<?php
use Livewire\Component;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Validate;

#[Layout('layouts.auth')]
new class extends Component {
    #[Validate('required|min:3')]
    public string $name = '';

    public function save() {
        $this->validate();
        // ...
    }
};
?>
<div>...</div>
```

### Functional SFC (Volt style)
```php
<?php
use function Livewire\Volt\{state, rules, layout};

layout('layouts.auth');
state(['name' => '']);
rules(['name' => 'required|min:3']);

$save = function () {
    $this->validate();
    // ...
};
?>
<div>...</div>
```

## Routing
Register routes in `routes/web.php`:
```php
Route::livewire('/dashboard', 'admin.dashboard');
// Maps to: resources/views/pages/admin/⚡dashboard.blade.php
```

## Template Syntax
- **Reactivity**: `wire:model="prop"` or `wire:model.live="prop"`
- **Actions**: `wire:click="method"`, `wire:submit="method"`
- **Events**: `<livewire:child @saved="$refresh" />`
- **Loading**: `<div wire:loading>...</div>`
- **Confirmation**: `wire:confirm="Are you sure?"`

## Attributes
- `#[Layout('name')]`: Define the wrapper layout.
- `#[Title('title')]`: Set the page title.
- `#[Locked]`: Prevent client-side updates to a property.
- `#[Url]`: Bind property to a URL query parameter.
- `#[On('event')]`: Listener for dispatched events.
- `#[Validate('rules')]`: Real-time and submission validation.

## Lifecycle Hooks
- `mount()`: Initial load only.
- `boot()`: Every request.
- `updating($prop, $val)` / `updated($prop, $val)`
- `rendering()` / `rendered()`
