DEV Community

Cover image for 3 Steps to Speed Up Laravel Projects with Laravel Shift Blueprint
Akram Ghaleb
Akram Ghaleb

Posted on

3 Steps to Speed Up Laravel Projects with Laravel Shift Blueprint

If you’re looking to cut down on repetitive coding tasks and get your Laravel projects off the ground faster, Laravel Shift Blueprint is the tool for you! Here’s a streamlined guide on how to use Blueprint effectively in three easy steps.


1. Install Blueprint

To get started, install Blueprint in your development environment using Composer:

composer require --dev laravel-shift/blueprint
Enter fullscreen mode Exit fullscreen mode

Blueprint is a development-only package, so it’s best to install it with the --dev flag. This ensures it won’t be included in your production environment, keeping your deployment lean and clean.


2. 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
Enter fullscreen mode Exit fullscreen mode

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.


3. 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
Enter fullscreen mode Exit fullscreen mode

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.

Give Laravel Shift Blueprint a try, and see how it can transform your Laravel workflow, helping you build features faster and more efficiently.

Happy coding! 🚀

Top comments (0)