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

Laravel Vuejs 实战:开发知乎 (5)设计问题表的更多相关文章

  1. Laravel Vuejs 实战:开发知乎 (6)发布问题

    1.view部分: 安装一个扩展包:Laravel-UEditor composer require "overtrue/laravel-ueditor:~1.0" 配置 添加下面 ...

  2. Laravel Vuejs 实战:开发知乎 (10)使用 Select2 优化话题选择

    1.添加选择Topic 使用Select2,如何安装Select2 ,具体使用实例 Select2 and Laravel: Ajax Autocomplete 及 Loading data remo ...

  3. Laravel Vuejs 实战:开发知乎 (1)项目环境配置和用户表设计

    1.使用laragon新建laravel项目 zhihu 2.配置env文件的database设置 DB_DATABASE=zhihu 3.分析users表需要的字段 4.修改数据库迁移文件: cla ...

  4. Laravel Vuejs 实战:开发知乎 (9)定义话题与问题关系

    1.话题[Topic] 执行命令: php artisan make:model Topic –cmr 修改****_**_**_create_topics_table.php数据库迁移文件如下: c ...

  5. Laravel Vuejs 实战:开发知乎 (8)美化编辑器

    1.使用UEditor增量包: simple-ueditors 执行下载: git clone https://github.com/JellyBool/simple-ueditor.git 2.用此 ...

  6. Laravel Vuejs 实战:开发知乎 (3)本地化和自定义消息

    1.本地化 由于所有blade默认采用的是 _('')方式输出标签文本,所以可以安装一个语言包,直接指定本地语言为zh_CN即可: 安装 https://github.com/caouecs/Lara ...

  7. Laravel Vuejs 实战:开发知乎 (2)用户登录

    1.安装一个给用户提示的扩展包: 二选一: https://github.com/laracasts/flash [我选的这个]https://github.com/oanhnn/laravel-fl ...

  8. Laravel Vuejs 实战:开发知乎 (2)用户注册

    1.本节需要发送验证邮件 2.教程使用SendCloud发送邮件 [我使用的是mailtrap] 3. composer require laravel/ui 安装完成后 php artisan ui ...

  9. Laravel Vuejs 实战:开发知乎 (7)验证问题表单字段

    上一节代码中已经实现 下面代码中的validate内部配置就是: public function store(Request $request) { // $data = $request->v ...

随机推荐

  1. centos7下top free vmstat 命令详情

    top:https://www.cnblogs.com/makelu/p/11169270.html

  2. Selenium3+python自动化009- js之屏幕滑动和日历操作

    一.js的滑屏 1)以下脚本实现js滑屏scroll="document.documentElement.scrollTop=800"#垂直滚动 pxscroll = " ...

  3. jdbc中SQL语句拼接java变量

    例如:String sql = "select * from user where username='" + username + "' and password =' ...

  4. IDEA编写shell脚本并运行

    1.去官网下载IDEA开发工具 https://www.jetbrains.com/idea/ 2.打开IDEA并安装bashsupport插件 3.安装完插件重启IDEA 4.下载git工具 htt ...

  5. AcWing 12. 背包问题求具体方案

    //f[i][j]=max(f[i-1][j],f[i-1][j-v[i]]+w[i]) #include <iostream> using namespace std; ; int n, ...

  6. AcWing 894. 拆分-Nim游戏

    #include <cstring> #include <iostream> #include <algorithm> #include <unordered ...

  7. C语言结构体理解

    本质就是数学中集合,里面变量相当于元素,难点在于就是:以前做数学题都是别人给了一个集合,算里面的关系,编程不一样的就是,自己定义一个集合.

  8. Netcat工具

    一般Netcat有两个版本,一个版本是不提供反向连接的版本,一个是全功能版本.这两者的区别就是是否带-e参数,只有带-e参数的版本才支持反向连接. 参数说明 -c shell commands she ...

  9. python面试的100题(6)

    7.请反转字符串 "aStr"? print("aStr"[::-1]) python实现字符串反转 第一种:使用字符串切片 result = s[::-1] ...

  10. quartus在线调试的方法

    quartus在线调试的方法 在Quartus II Version 7.2 Handbook Volume 3: Verification中的Section V. In-System Design ...