# Livewire 4.x Workflows

## Form Objects
Encapsulate form logic into a dedicated class for cleaner components.

```php
// app/Livewire/Forms/PostForm.php
namespace App\Livewire\Forms;
use Livewire\Form;
use Livewire\Attributes\Validate;
use App\Models\Post;

class PostForm extends Form {
    #[Validate('required|min:5')]
    public $title = '';

    #[Validate('required')]
    public $content = '';

    public function store() {
        $this->validate();
        Post::create($this->all());
        $this->reset();
    }
}

// resources/views/pages/admin/⚡create-post.blade.php
new class extends Component {
    public PostForm $form;
    public function save() {
        $this->form->store();
        return $this->redirect('/posts', navigate: true);
    }
};
```

## Global Event Communication
Communicate between components using dispatch and listeners.

```php
// Dispatcher
public function save() {
    // ...
    $this->dispatch('post-created', title: $this->title);
}

// Listener (in another component)
use Livewire\Attributes\On;

#[On('post-created')]
public function notify($title) {
    session()->flash('message', "New post created: {$title}");
}
```

## URL Query Parameters
Sync component properties with the URL.

```php
use Livewire\Attributes\Url;

new class extends Component {
    #[Url(history: true)]
    public string $search = '';

    public function with() {
        return [
            'results' => Post::where('title', 'like', "%{$this->search}%")->get(),
        ];
    }
};
```

## Navigation (SPA Mode)
Enable instant page transitions using `wire:navigate`.

```html
<!-- In Layout or Component -->
<nav>
    <a href="/" wire:navigate>Home</a>
    <a href="/dashboard" wire:navigate>Dashboard</a>
</nav>

<!-- In PHP Logic -->
$this->redirect('/path', navigate: true);
```
