teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

マイグレーションファイルを追記

2020/10/30 02:28

投稿

pup-ganbaru
pup-ganbaru

スコア29

title CHANGED
File without changes
body CHANGED
@@ -70,4 +70,68 @@
70
70
  $user->sites()->attach($request->site_id);
71
71
  return redirect()->route('store.index');
72
72
  }
73
+ ```
74
+
75
+ マイグレーションファイル
76
+
77
+ site_user_table.php
78
+ ```ここに言語を入力
79
+ */
80
+ public function up()
81
+ {
82
+ Schema::create('site_user', function (Blueprint $table) {
83
+ $table->id();
84
+ $table->timestamps();
85
+ });
86
+ }
87
+
88
+ ```
89
+
90
+ add column site_user table php
91
+ ```ここに言語を入力
92
+ */
93
+ public function up()
94
+ {
95
+ Schema::table('site_user', function (Blueprint $table) {
96
+ $table->unsignedBigInteger('user_id');
97
+ $table->unsignedBigInteger('site_id');
98
+ $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
99
+ $table->foreign('site_id')->references('id')->on('sites')->onDelete('cascade');
100
+ });
101
+ }
102
+ ```
103
+
104
+
105
+ user table php
106
+ ```ここに言語を入力
107
+ public function up()
108
+ {
109
+ Schema::create('users', function (Blueprint $table) {
110
+ $table->id();
111
+ $table->string('name');
112
+ $table->string('email')->unique();
113
+ $table->timestamp('email_verified_at')->nullable();
114
+ $table->string('password');
115
+ $table->rememberToken();
116
+ $table->foreignId('current_team_id')->nullable();
117
+ $table->text('profile_photo_path')->nullable();
118
+ $table->timestamps();
119
+ });
120
+ }
121
+
122
+ ```
123
+
124
+ site table php
125
+ ```ここに言語を入力
126
+ public function up()
127
+ {
128
+ Schema::create('sites', function (Blueprint $table) {
129
+ $table->id();
130
+ $table->string('site_name');
131
+ $table->string('site_url');
132
+ $table->boolean('delete_flg');
133
+ $table->softDeletes();
134
+ $table->timestamps();
135
+ });
136
+ }
73
137
  ```