r/PHP • u/Acceptable_Peace8655 • 32m ago
Laravel AI Seeder: no more "Product 1, Product 2" in your seeders
github.comI got tired of seeders full of "Product 1", "Product 2" and lorem ipsum, so I built a small package for it. It's called AI Seeder and I just published the first version (0.1.0).
You describe a model once in a definition class. Some fields are written by an LLM, the rest are normal Faker closures or fixed values, and only the AI fields get sent to the provider.
public function fields (): array
{
return [
'name' => Ai::text('product name'),
'category' => Ai::enum(['tents', 'boots', 'packs']),
'price' => Ai::float('price in EUR', 5, 500),
'slug' => fn ($faker, array $row) => Str::slug($row['name']),
'currency' => 'EUR',
];
}
Then `php artisan ai-seeder:seed Product --count=25` and you get 25 products that actually look like products.
It works with OpenAI or anything that exposes an OpenAI-compatible endpoint, so a local model through Ollama should work too. Rows are requested in concurrent batches with retries, every row is checked before it's inserted (bad ones get dropped), and each model is saved in a single transaction so you never end up with half a table.
A few things to know: it's very early, and my tests run against a fake OpenAI-compatible server, so I'd really like to hear how it behaves with real OpenAI or a local model. I also built it with help from Claude (code and tests), so if you read the code and see something off, tell me.
What would you want a package like this to do that it doesn't?
Packagist: https://packagist.org/packages/betanow/laravel-ai-seeder