How to use Laravel Blueprint Package?
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.
To quickly install Composer in the current directory, run the following script in your terminal. To automate the…
If you want use another way to install your laravel, you can follow below link to find another option.
Laravel is a web application framework with expressive, elegant syntax. A web framework provides a structure and…
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.
published_at: nullable timestamp user_id: integer
belongsTo: User User:
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.
validate: title, content, author_id
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 !
- Models -> Relations
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 :
Blueprint Official Resource :
Blueprint | Getting Started
Blueprint is an open-source tool for rapidly generating multiple Laravel components from a single, human readable…
Enjoy your coding !
BackEnd Developer, Social Thinker & Farmer