2019_02_27_102408_groups_users.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. use Illuminate\Support\Facades\Schema;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Database\Migrations\Migration;
  5. class GroupsUsers extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. *
  10. * @return void
  11. */
  12. public function up()
  13. {
  14. Schema::create('groups_users', function (Blueprint $table) {
  15. $table->unsignedInteger('user_id');
  16. $table->foreign('user_id', 'fk_users')
  17. ->references('id')
  18. ->on('users')
  19. ->onDelete('cascade');
  20. $table->unsignedInteger('group_id');
  21. $table->foreign('group_id', 'fk_groups')
  22. ->references('id')
  23. ->on('groups')
  24. ->onDelete('cascade');
  25. });
  26. }
  27. /**
  28. * Reverse the migrations.
  29. *
  30. * @return void
  31. */
  32. public function down()
  33. {
  34. Schema::table('groups_users', function (Blueprint $table) {
  35. $table->dropForeign('fk_users');
  36. $table->dropForeign('fk_groups');
  37. });
  38. Schema::dropIfExists('groups_users');
  39. }
  40. }