Skip to content

SQL to Laravel Models

Convert a MySQL or MariaDB dump into Laravel migrations, Eloquent models, factories and seeders together, with relationships detected, live in your browser.

Generate

Read in your browser and never uploaded. Only CREATE TABLE, ALTER TABLE and CREATE INDEX are read; INSERT data is skipped. Importing replaces the schema you are designing.

Add a table on the left, load an example, or open a project file to start designing.

Generated files

Generated files appear here as you design.

Diagnostics appear here after you paste your input.

Processed locally in your browser. Your data never leaves your device.

About this SQL to Laravel Models converter

Paste the structure of a MySQL or MariaDB database and get a working Laravel model layer: migrations, Eloquent models with relationships already wired up, factories that produce plausible fake data, and seeders — not just the migrations. This page is the full-scaffold entry point of the Database Schema Studio; the schema stays fully editable once imported, and every file group can be switched on or off.

A worked example

A users table and a posts table with a foreign key on user_id produce a model with the relationship already written:

class User extends Model
{
    use HasFactory;

    public $timestamps = false;

    /**
     * The attributes that are mass assignable.
     *
     * @var list<string>
     */
    protected $fillable = [
        'name',
        'email',
    ];

    public function posts(): HasMany
    {
        return $this->hasMany(Post::class);
    }
}

and a factory that fills every fillable column with a plausible value:

public function definition(): array
{
    return [
        'name' => fake()->name(),
        'email' => fake()->unique()->safeEmail(),
    ];
}

Note email is unique in the schema, so the factory calls fake()->unique() — a schema fact (a unique index), not a guess from the column's name.

How to use it

  1. Paste CREATE TABLE statements or a structure-only dump, or open a .sql file, then Import.
  2. Confirm any inferred relationships (a pivot table, a polymorphic pair) the diagnostics ask about.
  3. Choose which file groups to generate and how many rows each seeder creates.
  4. Copy or download each file, or download them all as one ZIP.

Frequently asked questions

How is this different from SQL to Laravel Migration?
That page turns models, factories and seeders off and shows only migrations. This page is the same studio with them turned on: migrations plus Eloquent models (with relationships detected from foreign keys), factories (Faker-backed, using a column’s name and type to pick a plausible value) and seeders. Switch anything off in Generate at any time — it is one studio, not a different converter.
How does it decide relationships?
Every foreign key becomes a belongsTo on the child and a hasMany (or hasOne, if the foreign key column is unique) on the parent. A junction table with exactly two foreign keys and no other meaningful columns is read as a many-to-many pivot: both sides get belongsToMany and the pivot table gets no model of its own — shown to you first as an inferred relationship you confirm, never assumed silently.
What does a factory actually fill in?
Every column a migration would ask for except ones the database or Eloquent fills in itself (an auto-increment key, managed timestamps). A column is matched by name first (email, name, slug, phone, and about twenty others get a plausible Faker call) and by its type otherwise. A password column gets a shared hashed “password” value, the same way Laravel’s own default factory stub does.
Is my SQL uploaded?
No. Reading and generating happen in your browser. Nothing is sent anywhere or stored.