Livewire Fakeable

Fill empty Livewire component state with realistic Faker data during local development. After mount, only on your machine, never overwriting values you already set.

Tests Downloads Version License
$ composer require tomeasterbrook/livewire-fakeable click to copy

Features

Everything you need to fill your Livewire components with realistic data while you build.

🎯

Explicit Formatters

Use any Faker formatter directly on properties. Pass arguments and seeds for full control.

🧠

Automatic Inference

Bare #[Fakeable] infers the right formatter from the property name, type, or enum automatically.

📋

Array Shapes

Generate arrays of structured fake data with a simple shape definition and row count.

🎭

Enum Support

Unit, string-backed, and int-backed enums are detected and filled with a random case.

📝

Livewire Forms

Attributes on Livewire\Form subclass properties are resolved automatically.

🔒

Safe by Default

Four-layer guard: enabled flag, local env, host allowlist, and Faker availability. Never runs in production.

Usage

Property-level formatters

Annotate public properties with #[Fakeable] and a Faker formatter name. Only null, '', or [] properties are filled — values set in mount() are never overwritten.

use Livewire\Component;
use TomEasterbrook\LivewireFakeable\Attributes\Fakeable;

class EditProfilePage extends Component
{
    #[Fakeable('name')]
    public string $name = '';

    #[Fakeable('safeEmail')]
    public string $email = '';

    #[Fakeable('paragraph')]
    public string $bio = '';
}

Bare #[Fakeable] — automatic inference

Skip the formatter and let the package figure it out. It checks the enum type, then the property name, then the PHP type.

#[Fakeable]
public string $email = '';       // inferred → safeEmail

#[Fakeable]
public int $quantity = 0;        // inferred → randomNumber

#[Fakeable]
public OrderStatus $status;      // inferred → random enum case

Seeds & arguments

Fix a seed for deterministic values (great for screenshots and demos), or pass arguments through to the Faker method.

#[Fakeable('sentence', nbWords: 3)]
public string $title = '';

#[Fakeable('name', seed: 42)]
public string $name = '';

Array shapes

Generate arrays of structured data with a shape definition and a count.

#[Fakeable(['name' => 'name', 'email' => 'safeEmail'], count: 3)]
public array $users = [];

State classes

For complex components, point #[Fakeable] at an invokable class that receives a Faker generator and returns an array keyed by property name.

use Faker\Generator;

class ProfileFormState
{
    public function __invoke(Generator $faker): array
    {
        return [
            'name'  => $faker->name(),
            'email' => $faker->safeEmail(),
        ];
    }
}

// On the component:
#[Fakeable(ProfileFormState::class)]
class EditProfilePage extends Component { ... }

Livewire Form objects

Attributes on Livewire\Form subclass properties are resolved automatically — no extra setup.

use Livewire\Form;
use TomEasterbrook\LivewireFakeable\Attributes\Fakeable;

class ProfileForm extends Form
{
    #[Fakeable('name')]
    public string $name = '';

    #[Fakeable('safeEmail')]
    public string $email = '';
}

HasFakeable trait

For programmatic control, use the trait and call fakeable() from mount(). The same guard conditions apply.

use TomEasterbrook\LivewireFakeable\Concerns\HasFakeable;

class EditProfilePage extends Component
{
    use HasFakeable;

    public function mount(): void
    {
        $this->fakeable(ProfileFormState::class);
    }
}

Safety

Livewire Fakeable is for local development only. Faking runs only when all four conditions pass. If any fails, nothing happens — no properties touched, no banner injected.

enabled is true in config

App environment is local

Request host matches allowed_hosts glob pattern

Faker\Generator class exists

Because APP_ENV=testing is not local, your test suite is unaffected.

Configuration

Publish the config file to customise behaviour:

$ php artisan vendor:publish --tag="livewire-fakeable-config"
// config/fakeable.php
return [
    'enabled'        => env('FAKEABLE_ENABLED', true),
    'allowed_hosts'  => ['*.test', '*.dev', 'localhost'],
    'locale'         => 'en_US',
    'show_indicator' => true,
];