## Auto-run a Filament Action on Page Load (Based on a URL Parameter)

This pattern lets you **trigger a Filament page action automatically when the page loads**, based on **query parameters** in the URL.

Typical use cases:
- Redirect a user back to a list page and automatically open a **Create modal**
- Auto-run a **Table action** (e.g. “Start onboarding”) when `?onboard=1` is present
- Pre-fill a form when `?template=xyz` is provided

---

## The idea

1. Bind a query parameter to a Livewire property using `#[Url]`
2. In `mount()`, check the parameter and set a `$defaultAction`
3. Filament will automatically run that action on page load

> If no parameter is present, no action runs and the page behaves normally.

---

## Example: Auto-open a header Create modal via `?create=1`

### URL
- `/admin/things` → normal page load (no action)
- `/admin/things?create=1` → auto-runs the action named `createThing`

### Page code (example)

```php
<?php

namespace App\Filament\Resources\ThingResource\Pages;

use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
use Livewire\Attributes\Url;
use App\Filament\Resources\ThingResource;

class ListThings extends ListRecords
{
    protected static string $resource = ThingResource::class;

    // Binds ?create=1 to $autoCreate
    #[Url(as: 'create')]
    public ?string $autoCreate = null;

    /**
     * Filament will run this action automatically on page load
     * if it's set to the name of an existing action.
     */
    public $defaultAction = null;

    public function mount(): void
    {
        parent::mount();

        // If the URL param is present, auto-run the action
        if (! empty($this->autoCreate)) {
            $this->defaultAction = 'createThing';
        }
    }

    protected function getHeaderActions(): array
    {
        return [
            CreateAction::make('createThing')
                ->label('Create Thing')
                ->modalHeading('Create a Thing')
                ->fillForm(fn () => [
                    // optional: prefill values when opened via URL
                    'status' => 'draft',
                ]),
        ];
    }
}
