Laravel AI Faker is a package that enhances Laravel's default Faker functionality by leveraging AI to generate realistic, context-aware fake data. This package scans your models, analyzes their attributes and relationships, and produces meaningful data for development and testing environments.
- AI-Powered Data Generation: Generates more realistic fake data using AI (e.g., OpenAI).
- Model Analysis: Automatically detects model attributes and relationships to provide context-aware data.
- Seamless Integration: Works seamlessly with Laravel factories and database seeding.
- Configurable: Customize AI prompts and settings for tailored results.
Require the package via Composer:
composer require kimani/laravel-ai-faker
If you're using AI services like OpenAI, publish the configuration file:
php artisan vendor:publish --provider="Kimani\AIFaker\AIFakerServiceProvider"
Then, add your API key to the configuration file or .env
file:
AIFAKER_API_KEY=your-api-key-here
Use the AIFaker
service in your factories:
use Kimani\AIFaker\Services\AIFaker;
$aiFaker = app(AIFaker::class);
return $aiFaker->generateFakeData(new \App\Models\YourModel());
In your Laravel factory:
use Kimani\AIFaker\Services\AIFaker;
/** @var \Kimani\AIFaker\Services\AIFaker $aiFaker */
$aiFaker = app(AIFaker::class);
\App\Models\YourModel::factory()->define(function () use ($aiFaker) {
return $aiFaker->generateFakeData(new \App\Models\YourModel());
});
The configuration file (config/aifaker.php
) allows you to customize:
- AI provider and API key
- AI model and parameters
- Default behavior for data generation
Run the tests with:
vendor/bin/phpunit
Contributions are welcome! Please submit a pull request or open an issue to report bugs or suggest features.
This package is open-source and licensed under the MIT License.
Developed by David Kimani.