Blueprint is an open-source tool for rapidly generating multiple Laravel components from a single, human readable definition.
Watch a quick demo of Blueprint in action and continue reading this document to get started.
Blueprint requires a Laravel application running version 6.0 or higher.
You can install Blueprint via composer using the following command:
composer require --dev laravel-shift/blueprint
Blueprint will automatically register itself using package discovery.
Blueprint comes with a set of artisan commands. The one you'll use the most is the blueprint:build
command to generate the Laravel components:
php artisan blueprint:build [draft]
The draft file contains a definition of the components to generate.
Let's review the following, example draft file to generate some blog components:
models:
Post:
title: string:400
content: longtext
published_at: nullable timestamp
controllers:
Post:
index:
query: all
render: post.index with:posts
store:
validate: title, content
save: post
send: ReviewNotification to:post.author with:post
dispatch: SyncMedia with:post
fire: NewPost with:post
flash: post.title
redirect: post.index
From these simple 20 lines of YAML, Blueprint will generate all of the following Laravel components:
- A model class for
Post
complete withfillable
,casts
, anddates
properties, as well as relationships methods. - A migration to create the
posts
table. - A factory intelligently setting columns with fake data.
- A controller class for
PostController
withindex
andstore
actions complete with code generated for each statement. - Routes for the
PostController
actions. - A form request of
StorePostRequest
validatingtitle
andcontent
based on thePost
model definition. - A mailable class for
ReviewNotification
complete with apost
property set through the constructor. - A job class for
SyncMedia
complete with apost
property set through the constructor. - An event class for
NewPost
complete with apost
property set through the constructor. - A Blade template of
post/index.blade.php
rendered byPostController@index
.
Browse the Blueprint Docs for full details on defining models, defining controllers, advanced configuration, and extending Blueprint.