How to use Laravel Blueprint Package?

Laravel Blueprint Package

Hello everyone!

I’m here again to share new experiences with you ! I just discovered a new Laravel Package named BluePrint which lets you create faster models, controllers, requests, resources and more. I can say, you can create a blog script without coding. :) Yeah, it’s possible and only you need to know Laravel development rules. Let me show you how it’s possible.

What is BluePrint ?

Blueprint is an open-source tool for rapidly generating multiple Laravel components from a single, human-readable definition.

Blueprint gives us to develop basic applications without coding. It just needs a YAML file that explains to app’s structure with models, controllers, relations. You can install it easily and I will share official document with you. You can find more options to create your application easier and faster. It’s really faster because you will be developed a lot of steps of any app with a YAML file.

When you run blueprint, it will generate also migrations, factories, even tests if you want to create also controllers. Let’s see how it happens.

How to install BluePrint ?

Firstly, you need to install your Laravel. I will show you the steps with you but I will be using the COMPOSER. If your system missing this package manager, you can install it. You can follow the below link to install it.

If you want use another way to install your laravel, you can follow below link to find another option.

We can install laravel as running below comman in your terminal :

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

After a few seconds, it will be installed laravel to your local. (You need to be sure, your device has an internet connection.)

Now, we can install blueprint with composer. (Use Terminal)

composer require --dev laravel-shift/blueprint

Yes, it’s all ! You are ready to use blueprint but how ?

How to create Models with Blueprint ?

For example, we want to develop a blog script and we need a posts table and model.

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

First, you need to use “models:” option to describe your models, and then, you will declare your model name. In our example, we will use POST and USER names for our model. After that, we need to declare columns and their properties like our example. As you see, we describe relations too. :) Isn’t awesome? It will save time for your development cycle.

You can describe your controllers with the “controllers:” option. If you describe validation in your YAML, blueprint will generate also your requests. :) In our example, I used the resource option. It will generate also resources for that controllers. :) Even you can respond to blade view, then the blueprint will generate also your view in the resources file. You can check official page of blueprint for more details.

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

As you see our controllers example, there is query option. It will generate a model query for us.

Let’s see the result as surprise in your local!

Run the below command in your terminal (You need to be sure, your YAML file location and name are correct.)

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

Now, let’s check below files and see what’s created there !

  • Controllers
  • Models -> Relations
  • Request
  • Resource
  • Database/migrations
  • Tests

If you check the above file, you will see the result of blueprint. It will be generated it all and more !

Thank you so much for your time ! :)

If you have any questions or recommendations, please don’t be hesitate to comment or mail me !

Blueprint GitHub Resource :

https://github.com/laravel-shift/blueprint/

Blueprint Official Resource :

Enjoy your coding !

Enver ŞANLI

BackEnd Developer, Social Thinker & Farmer

--

--

--

Back-End Developer

Recommended from Medium

Go: Writing, Testing and Benchmarking part 2

Me, search and share — the triangle of an efficient organisation ?

The perils of Bash ‘eval’

Python comes to rescue again — Electives Allocation

Exception Handling in Rails

Why we use Ruby on Rails to build GitLab

Best practices when using Databricks notebooks in an automated workflow

Swift & Objective-C Mixed Languages App

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Enver Şanlı

Enver Şanlı

Back-End Developer

More from Medium

Add And Store Data In Laravel 8

Build Web App Mini Sosmed with Laravel 8 [Part 4]

Laravel Real-Time Notifications with Pusher

How to Create Database Backup in Laravel

How to Create Database Backup in Laravel