Laravel Blueprint Package: A Step-by-Step Tutorial for Beginners

We will be looking at the Laravel Blueprint Package in this blog article, which enables you to design models, controllers, requests, resources, and other features quickly.

You can write a blog script without knowing any code by using Laravel Blueprint. For Laravel developers, Laravel Shift Blueprint is a code generation tool created by Jason McCreary.

Although it sounds absurd, it is feasible if you are familiar with Laravel development guidelines. Let’s begin your adventure to discover how this is achievable.

What is Larvel Blueprint?

An open-source tool called Laravel Blueprint can quickly create several Laravel components from a single, clear specification.

Blueprints enable us to create simple apps without the need for coding. To explain the program’s structure with models, controllers, and relations, all it takes is a YAML file.

We will provide you with the official document, which you may install with ease. More options are available to make the process of creating your application quicker and easier.

It’s easier to use because a YAML file can be used to construct many of the processes in any project.

If you wish to develop controllers as well, running a blueprint will also produce factories, tests, and migrations.

Let’s see how this magic is going to happen in a step-by-step process.

How to Install Laravel Blueprint Package?

The first thing you must do is install Laravel on your computer.

Let’s start by using the COMPOSER as we guide you through the process of installing the Laravel blueprint package.

Installing this package manager is simple if it isn’t already on your system. Using the command below in your terminal, you can easily install the Laravel framework in your system:

composer create-project laravel/laravel your-app-name

The Laravel framework can be installed on your computer in a matter of seconds by running the command mentioned above.

A reliable internet connection is essential for a smooth installation. Installing the blueprint with the composer can be done through the same terminal.

composer require --dev laravel-shift/blueprint

Indeed, that is everything! Once prepared, how will you use the blueprint?

Definitions of the components that Blueprint is supposed to generate are stored in a draft file (YAML). The readme offers a draft.yml file example located in the project root of a Laravel v6.x instance:

How to Create Models with Laravel Blueprint?

For instance, a posts table and model are required while developing a blog script.

models:
    Post:
        title: string:400
        content: longtext
        published_at: nullable timestamp
        user_id: integer
        relationships:
            belongsTo: User
        User:
            full_name: string:400
            email: string:255
            relationships:
                 hasMany: Post

You will declare your model name once you have used the “models:” option to describe your models. POST and USER names are used in our example for our model.

The next step is to declare the columns and their attributes as the example indicates. We also describe relations, as you can see.

Isn’t that fantastic? It will shorten the duration of your development cycle.

Using the “controllers:” option, you may describe your controllers. The blueprint will also build your requests if you include a description of validation in your YAML.

The resource option was employed in our case. It will produce resources for those controllers as well.

If you reply to the blade view as well, the blueprint will create your view in the resources file as well. To find out more information, visit the blueprint’s official website.

controllers:
    User:
        index:
            validate: title, content, author_id
            query: all
            resource: user

We’ve included a query option in our controllers example. A model inquiry will be produced for us by it. See the unexpected outcome in your local machine!

Make sure the location and name of your YAML file are accurate by running the following command in your terminal.

php artisan blueprint:build your-yaml-file.yaml

Let’s now look at the files below and see what was generated!

  • Models -> Relations
  • Controllers
  • Requests
  • Resources
  • Database/Migrations
  • Tests

The blueprint’s outcome can be seen if you look at the file mentioned above. It will be produced more than that.

Visit GitHub at laravel-shift/blueprint to read the source code, learn more about this package, and obtain comprehensive installation instructions.

For more information about the Laravel framework stay tuned with us or visit our laravel tutorial to learn more about this platform.

Kundan Chaudhary is an adept SEO Analyst and Content Writer, backed by an MSc. in IT from Islington College. His proficiency spans keyword research, SEO optimization (On Page, Off Page, and Technical), copywriting, proofreading, content strategy, and blogging.

Leave a Comment