Rapid application scaffolding with Laravel Blueprint

Hello there, In this tutorial we will see how to rapidly develop a Laravel application by utilising a code generation tool called Laravel Blueprint. Laravel Blueprint allows creating multiple Laravel components(Models, Controller,Event and others) from a single, human readable domain language.

Blueprint features

Draft your application with a simple syntax

Blueprint uses a simple YAML syntax to define your models and controllers offering shorthands and leveraging conventions to maximize the developer experience.

Generate code using artisan commands

Blueprint comes with artisan commands making it easy and familiar to build new components and reference existing within your Laravel application.

Output multiple Laravel components at once

Blueprint not only generates models and controllers, but factories, migrations, form requests, events, jobs, and mailables. Oh, and tests too. To start

Step 1. Create new laravel application

laravel new blue-app cd blue-app 
Enter fullscreen mode

Exit fullscreen mode

Step 2. Install Blueprint package

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

Exit fullscreen mode

Testing package for tests created
composer require --dev jasonmccreary/laravel-test-assertions 
Enter fullscreen mode

Exit fullscreen mode

Ignoring Blueprint files
echo '/draft.yaml' >> .gitignore echo '/.blueprint' >> .gitignore 
Enter fullscreen mode

Exit fullscreen mode

Step 3. Scaffold Application using YAML file

Create a draft.yaml file
touch draft.yaml 
Enter fullscreen mode

Exit fullscreen mode

Add the following
models: Post: title: string:400 content: longtext remark: string:100 nullable user_id: id foreign published_at: nullable timestamp relationships: hasMany: Transaction belongsTo: User Transaction: payment_token: string:40 total: decimal:8,2 user_id: id foreign post_id: id foreign:posts status: enum:pending,successful,failed relationships: belongsTo: User, Post seeders: Post, Comment controllers: Post: index: query: all:posts render: post.index with:posts create: render: post.create store: validate: title, content, remark save: post send: ReviewNotification to:post.author with:post dispatch: SyncMedia with:post fire: NewPost with:post flash: post.title redirect: post.index show: render: post.show with:post edit: render: post.edit with:post update: validate: post update: post flash: post.id redirect: post.index destroy: delete: post redirect: post.index Transaction: store: validate: transaction save: transaction flash: transaction.id redirect: post.index show: render: transaction.show with:transaction Report: invokable: fire: ReportGenerated render: report 
Enter fullscreen mode

Exit fullscreen mode

At this point we have many files to check and review before moving forward. This tutorial ends here the next step is optional.

Step 4. Scaffold Authentication (Optional)

Using the Breeze for Authentication code scaffolding.

composer require laravel/breeze --dev 
Enter fullscreen mode

Exit fullscreen mode

php artisan breeze:install 
Enter fullscreen mode

Exit fullscreen mode

npm install && npm run dev php artisan migrate 
Enter fullscreen mode

Exit fullscreen mode

Start the application

Start the development server

php artisan server 
Enter fullscreen mode

Exit fullscreen mode

Access from the browser at http:://localhost:8000