2017_09_09_152726_create_tags_table.php 880 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use Illuminate\Support\Facades\Schema;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Database\Migrations\Migration;
  5. class CreateTagsTable extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. *
  10. * @return void
  11. */
  12. public function up()
  13. {
  14. Schema::create('tags', function (Blueprint $table) {
  15. $table->increments('id');
  16. $table->string('name')->unique();
  17. $table->timestamps();
  18. });
  19. Schema::create('post_tag', function (Blueprint $table) {
  20. $table->integer('post_id');
  21. $table->integer('tag_id');
  22. $table->primary(['post_id', 'tag_id']);
  23. });
  24. }
  25. /**
  26. * Reverse the migrations.
  27. *
  28. * @return void
  29. */
  30. public function down()
  31. {
  32. Schema::dropIfExists('post_tag');
  33. Schema::dropIfExists('tags');
  34. }
  35. }