mgamal92/filament-demo-generator

Generate demo data for any Filament resource

v1.4.0 2025-07-16 07:10 UTC

This package is auto-updated.

Last update: 2025-07-16 07:14:15 UTC


README

A Filament plugin that helps you generate realistic demo data for any resource — in just one click.

Whether you're testing layouts, showcasing features, or kicking off a new dashboard — skip writing manual seeders and fill your tables instantly.

Features

  • One smart "Generate / Delete Demo Data" button added to any resource
  • Dynamic label, color, and modal content based on state
  • Custom modal with option to set number of records
  • Built-in delete confirmation for demo data
  • Caches generated record IDs for precise cleanup
  • Fires DemoDataGenerated event after creation for extensibility
  • Smart field detection using fillable
  • Auto-handles BelongsTo relationships
  • Enum fields are fully supported — random value selected automatically
  • Faker-powered values based on field types
  • Supports text, number, email, dates, enums, and more
  • Fully extendable — hook into the generator or replace logic as needed

BelongsTo Relationships

The package automatically handles BelongsTo relationships:

  • If related records exist, a random one is selected and linked.
  • If no related records are found, a new record is created and linked automatically.
  • This process does not require Laravel factories and works based on fillable attributes.

For example, if your model has a user_id field and a user() relationship, the generator will automatically populate it correctly.

Event: DemoDataGenerated

After demo data is created, the following event is fired:

Mgamal92\FilamentDemoGenerator\Events\DemoDataGenerated

You can listen to it like this:

use Mgamal92\FilamentDemoGenerator\Events\DemoDataGenerated;

Event::listen(DemoDataGenerated::class, function ($event) {
    logger('Demo generated for: ' . $event->model);
});

Payload includes:

  • $event->model
  • $event->count
  • $event->ids (array of record IDs)

Configuration

You can customize how fake demo data is generated by publishing the config file:

php artisan vendor:publish --tag=config --provider="Mgamal92\FilamentDemoGenerator\FilamentDemoGeneratorServiceProvider"

This will create a filament-demo-generator.php file in your config directory. You can customize:

  • Value generators for specific field names (e.g., "email", "phone")
  • Generators by column type (e.g., "string", "integer", "date")
  • Supported faker patterns

Installation

composer require mgamal92/filament-demo-generator

Usage

After installation, a "Generate Demo Data" button will appear in the table header of any Filament resource.

If demo data already exists, the same button becomes "Delete Demo Data", and deletes only the records it generated.

Contributing

Contributions are welcome!

If you have suggestions for improving the plugin, want to support new field types, or help with localization, feel free to open an issue or submit a pull request.

  1. Fork the repo
  2. Make your changes
  3. Submit a PR

License

MIT License