热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

LaravelVuejs实战:开发知乎(5)设计问题表

1.执行命令:1phpartisanmake:modelModelsQuestion-cm2.设计问题的数据库迁移文件中的字段:1bigIncrements('id'

1.执行命令:

1 php artisan make:model Models/Question -cm

2.设计问题的数据库迁移文件中的字段:
技术分享图片技术分享图片

1 php
2
3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Support\Facades\Schema;
6
7 class CreateQuestionsTable extends Migration
8 {
9 /**
10 * Run the migrations.
11 *
12 * @return void
13 */

14 public function up()
15 {
16 Schema::create(‘questions‘, function (Blueprint $table) {
17 $table->bigIncrements(‘id‘);
18 $table->string(‘title‘);
19 $table->text(‘content‘);
20 $table->integer(‘comments_count‘)->default(0);
21 $table->integer(‘followers_count‘)->default(1);//问题的关注者数量,默认1个【提问的人就是最开始关注的那个人】
22 $table->integer(‘answers_count‘)->default(0);
23 $table->string(‘close_comment‘, 8)->default(‘F‘);//问题是否被关闭评论 F默认否
24 $table->string(‘is_hidden‘, 8)->default(‘F‘);//问题是否被隐藏 F默认否
25 $table->timestamps();
26 });
27 }
28
29 /**
30 * Reverse the migrations.
31 *
32 * @return void
33 */

34 public function down()
35 {
36 Schema::dropIfExists(‘questions‘);
37 }
38 }
39

查看代码

上面的default(‘F’) 真就是’T’,不过有些习惯使用smallInterger然后默认设置值为0 ,真为1的方式也可以。

3. 执行命令:

1 php artisan migrate


推荐阅读
author-avatar
mobiledu2502854877
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有