- 創建 Topic model and migrate
php artisan make:model Topic -m
$table->increments('id'); $table->string('name'); $table->text('bio')->nullable(); $table->integer('question_count')->default(0); $table->integer('followers_count')->default(0); $table->timestamps();
- Topic 跟 Question 為多對多的關係
php artisan make:migration create_questions_topics_table --create=question_topic
$table->increments('id'); $table->integer('question_id')->unsigned()->inddex(); $table->integer('topic_id')->unsigned()->inddex(); $table->timestamps();
- Question.php
protected $fillable = ['title', 'body', 'user_id']; public function topics() { return $this->belongsToMany(Topic::class)->withTimestamps(); }
- Topic.php
public function questions() { return $this->belongsToMany(Question::class)->withTimestamps(); }
優化話題選擇
- 將
select2.min.js
及select2.min.css
放到resources/assets/css及js
底下 -
resources/assets/js/bootstrap.js
引入 select2.js
try { window.$ = window.jQuery = require('jquery'); require('bootstrap-sass'); require('./select2,min'); } catch (e) {}
resources/assets/sass/app.scss
引入 select2.css
@import "./../css/select2.min"
- 執行
gulp
,這裡使用mix
> Laravel 的资源任务编译器 Laravel Mix | Laravel 5.5 中文文档
> https://gulpjs.com/
#後端學習/Laravel/知乎