Framework

Seed Laravel + MySQL with MockHero

Seeder

// database/seeders/MockHeroSeeder.php
<?php
namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;

class MockHeroSeeder extends Seeder {
  public function run(): void {
    $res = Http::withHeaders(["x-api-key" => env("MOCKHERO_API_KEY")])
      ->post("https://api.mockhero.dev/api/v1/generate", [
        "tables" => [
          ["name" => "users", "count" => 50, "fields" => [
            ["name" => "id", "type" => "uuid"],
            ["name" => "email", "type" => "email"],
          ]],
          ["name" => "orders", "count" => 200, "fields" => [
            ["name" => "id", "type" => "uuid"],
            ["name" => "user_id", "type" => "ref", "ref" => "users.id"],
            ["name" => "total", "type" => "price"],
          ]],
        ],
      ])
      ->json();

    DB::table("users")->insert($res["users"]);
    DB::table("orders")->insert($res["orders"]);
  }
}

Run with php artisan db:seed --class=MockHeroSeeder.

Get Started

Free API key.

M

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

Related Articles