Laravel Wizard, scaffolding your database how YOU want it

The YAML way to push your app from idea to code

Italo Baeza Cabrera
2 min readApr 29, 2020

Let’s be honest: the most boring thing about Laravel is creating the whole application database schema from scratch. While Laravel eases most of the development thanks for its artisan commands, you mostly go back and forth to synchronize the database schematics between the models, factories and seeders, praying everything connects.

It’s not easy task nor a short one:

  1. Create the Post model,
  2. connect the model with relationships,
  3. edit the posts migration,
  4. create the the factory and states,
  5. add database seeder,
  6. and probably add the PHP Docs to the properties of the Post model.
  7. Do the same all models you have in mind…
  8. … and you’ll probably miss something.

Not happy with Laravel Shift Blueprint, Scaffold Interface, Laravel Generator, among others that only offer CRUD, I decided to create something with a good documentation, is easy to pick up, stops if you’re doing something wrong, and does enough to let you start you own thing:

Larawiz

The Laravel Wizard we deserved but never got

Larawiz is short for “Laravel Wizard”, and aims to become one of those installation wizards where you check and uncheck what you want.

The way Larawiz works is by a simple YAML file, where from it will spawn almost everything you need, including effortless relationships.

models:  User:
name: string
email: string
password: string
posts: hasMany
Post:
uuid: ~
title: string
body: longText
author: belongsTo:User
comments: hasMany
Comment:
body: string
post: belongsTo

From that, Larawiz guesses most of the things, like the needed tables relations need to work an what not, automatic id, timestamps, and UUID as primary key, fillable properties, datetime casting, PHP Docs, migrations, factories, seeders, and what not.

You can even do some complicated things, like a polymorphic many-to-many relations, without ever having to think about the pivot model, since Larawiz will automatically guess that.

models:  Post:
name: string
tags: morphToMany:Tag,taggable
Video:
name: string
tags: morphToMany:Tag,taggable
Tag:
name: string
posts: morphedByMany:Post,taggable
videos: morphedByMany:Video,taggable

And if you don’t want to Larawiz help you, you have total control and useful warnings in case you do something wrong, like doing a Has Many Through relation without the needed columns.

There are a lot of examples and an extensive documentation if you are lost on how to proceed with scaffolding, you fear not, you don’t even need to read the documentation since the YAML file it includes is very self-explanatory.

The package is 99% stable, but you can test it in a fresh Laravel installation and see if it works for you. Give it a chance and tell me what you think.

--

--

Italo Baeza Cabrera
Italo Baeza Cabrera

Written by Italo Baeza Cabrera

Graphic Designer graduate. Full Stack Web Developer. Retired Tech & Gaming Editor. https://italobc.com

Responses (1)