Install Blueprint
To get started, install Blueprint in your development environment using Composer:
composer require --dev laravel-shift/blueprint
Create the Draft YAML File
The draft.yaml file is the heart of Blueprint—it’s where you define your models, controllers, relationships, and even routes! Start by creating a draft.yaml file in your project’s root directory.
Blueprint reads this file to understand the structure of your app. Here’s a sample setup for a blog:
models:
Post:
title: string
content: text
published_at: timestamp nullable
status: string
category_id: unsignedInteger nullable
relationships:
belongsTo: Category
belongsToMany: Tag, Author
Category:
name: string
description: string nullable
relationships:
hasMany: Post
Author:
name: string
email: string
bio: text nullable
twitter_handle: string nullable
relationships:
belongsToMany: Post
Tag:
name: string
slug: string
relationships:
belongsToMany: Post
This simple YAML file defines multiple models, fields, and relationships in one place, allowing you to model your entire app’s data structure with minimal syntax.
Generate Code with Blueprint
Once you’ve defined your models in draft.yaml, it’s time to let Blueprint work its magic. Run the following command to generate your code:
php artisan blueprint:build
This command reads draft.yaml and automatically generates models, migrations, controllers, and routes based on your specifications. You’ll see files created for each model and relationship, saving you from writing boilerplate code manually.
Bonus Tips for Optimizing Your Workflow
- Add Custom Attributes and Relationships: You can always modify draft.yaml to include more attributes or complex relationships as your app grows. For example, add unique constraints, nullable fields, and foreign keys.
- Regenerate on the Fly: Blueprint is not a one-time tool. As your app evolves, update your draft.yaml file and re-run php artisan blueprint:build. This will adjust your models, migrations, and other components without overwriting custom code you’ve already modified.
- Define Requests, Factories, and Controllers: Blueprint also supports defining form requests, factories, and custom controllers to help structure your application behavior in draft.yaml. This further speeds up development and maintains clean, well-organized code.
Conclusion
Give Laravel Shift Blueprint a try, and see how it can transform your Laravel workflow, helping you build features faster and more efficiently.
FAQs
Q: What is Laravel Shift Blueprint?
A: Laravel Shift Blueprint is a tool that helps you build features faster and more efficiently in Laravel by generating models, migrations, controllers, and routes based on your YAML file.
Q: How do I install Blueprint?
A: You can install Blueprint using Composer: composer require –dev laravel-shift/blueprint.
Q: What is the purpose of the draft.yaml file?
A: The draft.yaml file is where you define your models, controllers, relationships, and even routes for your app. Blueprint reads this file to understand the structure of your app.
Q: How do I generate code with Blueprint?
A: Run the following command to generate your code: php artisan blueprint:build. This command reads your draft.yaml file and generates models, migrations, controllers, and routes based on your specifications.

