Fill empty Livewire component state with realistic Faker data during local development. After mount, only on your machine, never overwriting values you already set.
Everything you need to fill your Livewire components with realistic data while you build.
Use any Faker formatter directly on properties. Pass arguments and seeds for full control.
Bare #[Fakeable] infers the right formatter from the property name, type, or enum automatically.
Generate arrays of structured fake data with a simple shape definition and row count.
Unit, string-backed, and int-backed enums are detected and filled with a random case.
Attributes on Livewire\Form subclass properties are resolved automatically.
Four-layer guard: enabled flag, local env, host allowlist, and Faker availability. Never runs in production.
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 = ''; }
#[Fakeable] — automatic inferenceSkip 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
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 = '';
Generate arrays of structured data with a shape definition and a count.
#[Fakeable(['name' => 'name', 'email' => 'safeEmail'], count: 3)] public array $users = [];
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 { ... }
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 traitFor 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); } }
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.
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, ];