【Tutorial】 How to build a blog contents quickly with Laravel 5.6 using crud-d-scaffold

Since the package “crud-d-scaffold” for Laravel 5.6 was renewed,
I will write a tutorial.

First, the image of the finish.
Below, it is a demo site.

Crud-d-Scaffold Demo Page
https://demo-cds.dog-ears.net/
*The top page and the footer are additionally fixed. It is not updated with Scaffold.

Index page
Default, 1 page displayed 10 items.
It can display search narrowing display by exact match with ID and partial match with schema contents.You can also sort.
By the way, if you display with a smartphone or the like, only the ID and the first column (TITLE in the example below) will be displayed.

Create page
Duplicate registration and editing are almost the same page.
Items connected by one-to-many relation are pulled down. (Only on many sides)
Items connected by many-to-many relation are entered by check box (if there is a column in the Pivot table, input by modal).

Detail page
Items connected by a one-to-many relation are displayed in a table.

Let’s make it.

First of all, the following shall be prepared.

  • A server that can connect to published SSH. If it is not, it can be cloud 9
  • Composer and php 7.1.3 and above and all php extensions shall be installed.

Please refer to the following for details of necessary requirement.

■Laravel 5.6 インストール
https://laravel.com/docs/5.6

(1) Installation of Laravel

After connecting to the server with SSH, move to the place you want to install, then execute

composer create-project --prefer-dist laravel/laravel ./[install folder]

When installation is completed, set the following in the install folder.

  • Set public directory to Apache’s public folder.
  • Make the directory under storage and the bootstrap / cache directory writable

DB setting
Fixed .env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_CONNECTION=sqlite
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=homestead
#DB_USERNAME=homestead
#DB_PASSWORD=secret

Make the following empty files writeable in [Install folder] / database /
database.sqlite

Your installation of Laravel is now complete.

(2) DB design

Open the following site

ER-DIAGRAM-TOOL
http://er.dog-ears.net/

First of all I will make a major model.

(i) post model

Edit – Create Model

Name:post
Display name:POST
use soft delete:checked

*Name is written in singular camel case (eg. NicePost)

Next, add the schema.
You can add a schema by pressing “add schema” on the added model.

Name:title
Display name:TITLE
Type:string
Input Type:text
Varidate:
Faker Type:sentence()
nullable:unchecked
unique:unchecked
show in list:checked
show in detail:checked

*Write Name in singular camel case (eg .bigTitle)
*See below for Varidate. However, as for required and unique, since it enters automatic with a check box, input is unnecessary.

Laravel 5.6 Validation – validation rules available
https://laravel.com/docs/5.6/validation#available-validation-rules

*For Faker Type, see below

github – fzaninotto/Faker
https://github.com/fzaninotto/Faker

When asked whether to set the schema to be displayed for the relation at the time of the first schema creation, it is OK. It is also possible to change it later on the model editing screen.

Add another schema in the same way

Name:body
Display name:BODY
Type:string
Input Type:textarea
Varidate:
Faker Type:paragraph()
nullable:checked
unique:unchecked
show in list:unchecked
show in detail:checked

*Because the text is long, it is not displayed on the list screen. Also, it is blankable.

(ii) tag model

— Edit – Create Model

Name:tag
Display name:TAG
use soft delete:checked

— add schema

Name:name
Display name:NAME
Type:string
Input Type:text
Varidate:
Faker Type:word()
nullable:unchecked
unique:checked
show in list:checked
show in detail:checked

*The name made unique

(iii) category model

— Edit – Create Model

Name:category
Display name:CATEGORY
use soft delete:checked

— add schema

Name:name
Display name:NAME
Type:string
Input Type:text
Varidate:
Faker Type:word()
nullable:unchecked
unique:checked
show in list:checked
show in detail:checked

(iv) comment model

— Edit – Create Model

Name:comment
Display name:COMMENT
use soft delete:checked

— add schema

Name:title
Display name:TITLE
Type:string
Input Type:text
Varidate:
Faker Type:sentence()
nullable:unchecked
unique:unchecked
show in list:checked
show in detail:checked

— add schema

Name:body
Display name:BODY
Type:string
Input Type:textarea
Varidate:
Faker Type:paragraph()
nullable:checked
unique:unchecked
show in list:unchecked
show in detail:checked

Next let’s relate
Dragging from the top right circle of each model to the circle of another model makes a relation.

The relation to make is as follows.

  • category -> post(one-to-many)
  • post -> comment(one-to-many)
  • post -> tag(many-to-many)

When it is many-to-many, Pivot table (intermediate table) is generated.
You can also add columns to the intermediate table.

In the post_tag model, add schema

Name:priority
Display name:PRIORITY
Type:integer
Input Type:text
Varidate:
Faker Type:numberBetween(1,10)
nullable:checked
unique:unchecked
show in list:checked
show in detail:checked

It turned out to be something like this.

Finally, download crud – d – scaffold.json with File – Save.

(3) Installing and executing the crud-d-scaffold package

Return to SSH and install the package

composer require dog-ears/crud-d-scaffold

crud-d-scaffold.json up to the Laravel installation folder.
Then execute

php artisan vendor:publish --tag=public --force
php artisan crud-d-scaffold:setup -f
php artisan migrate
php artisan db:seed

With this, you can check by opening public address / posts /.

Summary

I explained Crud-d-Scaffold which can scaffold with Laravel.
For now, I think that it is convenient when you want to make a simple application framework with Laravel.

I think that there are plenty of rough cuts yet, so I will keep updating in the future.

If you use it, if there is a problem, correction request, etc.,
I think that you can say more and more.

Thank you.

シェアする

  • このエントリーをはてなブックマークに追加

フォローする