A code generation tool for Laravel developers.
MIT License
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 or continue reading to get started.
Blueprint requires a Laravel application running a supported version of Laravel. Currently that is Laravel 10.38 or higher.
You can install Blueprint via Composer using the following command:
composer require -W --dev laravel-shift/blueprint
Blueprint will automatically register itself using package discovery.
If you wish to run the tests generated by Blueprint, you should also install the Additional Assertions package:
composer require --dev jasonmccreary/laravel-test-assertions
Blueprint comes with a set of artisan commands. The one you'll use to generate the Laravel components is the blueprint:build
command:
php artisan blueprint:build [draft]
The draft file contains a definition of the components to generate. Let's review the following example draft file which generates some blog components:
models:
Post:
title: string:400
content: longtext
published_at: nullable timestamp
author_id: id:user
controllers:
Post:
index:
query: all
render: post.index with:posts
store:
validate: title, content, author_id
save: post
send: ReviewPost to:post.author.email with:post
dispatch: SyncMedia with:post
fire: NewPost with:post
flash: post.title
redirect: posts.index
From these 20 lines of YAML, Blueprint will generate all of the following Laravel components:
Post
complete with fillable
, casts
, and dates
properties, as well as relationships methods.posts
table.PostController
with index
and store
actions complete with code generated for each statement.PostController
actions.StorePostRequest
validating title
and content
based on the Post
model definition.ReviewPost
complete with a post
property set through the constructor.SyncMedia
complete with a post
property set through the constructor.NewPost
complete with a post
property set through the constructor.post/index.blade.php
rendered by PostController@index
.PostController
.StorePostRequest
form request.Note: This example assumes features within a default Laravel application such as the User
model and app.blade.php
layout. Otherwise, the generated tests may have failures.
Browse the Blueprint Docs for full details on defining models, defining controllers, advanced configuration, and extending Blueprint.
Starting with version 2, Blueprint only generates code for supported versions of Laravel (currently Laravel 10.38 or higher). If you need to support older versions of Laravel, you may use version 1 or upgrade your application (try using Shift).
Blueprint still follows semantic versioning. However, it does so with respect to its grammar. Any changes to the grammar will increase its major version number. Otherwise, minor version number increases will contain new features. This includes generating code for future versions of Laravel.