Generate Fake Data for Laravel with the MockHero API
The Problem
Laravel ships with model factories and Faker, which is great until you need relational data. You define a UserFactory and a PostFactory, but connecting them requires afterCreating callbacks, state methods, and careful orchestration. For a real app with 10+ models, the factory system becomes hard to maintain.
Faker itself generates random data that often fails validation. Email domains do not resolve, phone numbers have wrong formats, and addresses mix countries with zip codes.
The Solution: MockHero API
MockHero generates validated, relational data in one API call. Define your models as a MockHero schema, use ref fields for foreign keys, and get back JSON you can insert through Eloquent.
Quick Setup
curl -X POST https://api.mockhero.dev/api/v1/generate \
-H "x-api-key: mh_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"tables": [
{
"name": "users",
"count": 10,
"fields": [
{ "name": "id", "type": "uuid" },
{ "name": "name", "type": "full_name" },
{ "name": "email", "type": "email" },
{ "name": "created_at", "type": "datetime" }
]
},
{
"name": "posts",
"count": 30,
"fields": [
{ "name": "id", "type": "uuid" },
{ "name": "user_id", "type": "ref", "params": { "ref": "users.id" } },
{ "name": "title", "type": "sentence" },
{ "name": "body", "type": "paragraphs" },
{ "name": "status", "type": "enum", "params": { "values": ["draft","published","archived"] } }
]
}
],
"format": "json"
}'
Step-by-Step Guide
1. Install dependencies
Laravel includes Guzzle by default. No extra packages needed.
2. Get your MockHero API key
Sign up at mockhero.dev/sign-up and add the key to your .env.
3. Create an Artisan command
Run php artisan make:command SeedFromMockHero and write a command that calls MockHero's API and inserts the data through Eloquent models.
4. Run it
php artisan seed:mockhero
5. Verify
Open Tinker or your admin panel to confirm the data was inserted with proper relationships.
Complete Example
The Artisan command replaces factories and seeders with a single API call that handles relational consistency through ref fields.
Why MockHero vs Faker / Factories
- No factory maintenance — schema changes are JSON updates, not PHP refactors.
- Relational out of the box —
reffields replace complexafterCreatingcallbacks. - Consistent data — pass a
seedparameter for deterministic output across environments.
Get Started
Free tier, no credit card. Sign up at mockhero.dev and seed your Laravel app in one Artisan command.
MockHero Team
Guides and tutorials for generating realistic test data with the MockHero API.
Start generating test data for free
1,000 rows/month on the free tier. No credit card required.
Get Your API Key