質問編集履歴
4
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
多対多のリレーション先テーブルの値をviewで表示できない
|
test
CHANGED
File without changes
|
3
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
中間テーブルの
|
1
|
+
中間テーブルのデータをviewで表示できない
|
test
CHANGED
File without changes
|
2
モデルを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -122,6 +122,104 @@
|
|
122
122
|
|
123
123
|
|
124
124
|
|
125
|
+
```ここに言語を入力
|
126
|
+
|
127
|
+
Store.php
|
128
|
+
|
129
|
+
<?php
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
namespace App\Models;
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
138
|
+
|
139
|
+
use Illuminate\Database\Eloquent\Model;
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
class Store extends Model
|
144
|
+
|
145
|
+
{
|
146
|
+
|
147
|
+
use HasFactory;
|
148
|
+
|
149
|
+
protected $table = 'stores';
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
// 店舗に所属する連携サイトを取得
|
154
|
+
|
155
|
+
public function sites()
|
156
|
+
|
157
|
+
{
|
158
|
+
|
159
|
+
return $this->belongsToMany('App\Models\Site');
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
```ここに言語を入力
|
172
|
+
|
173
|
+
site.php
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
<?php
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
namespace App\Models;
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
186
|
+
|
187
|
+
use Illuminate\Database\Eloquent\Model;
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
class Site extends Model
|
192
|
+
|
193
|
+
{
|
194
|
+
|
195
|
+
use HasFactory;
|
196
|
+
|
197
|
+
protected $table = 'sites';
|
198
|
+
|
199
|
+
protected $fillable = ['site_name', 'site_url'];
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
public function stores()
|
204
|
+
|
205
|
+
{
|
206
|
+
|
207
|
+
return $this->belongsToMany('App\Models\Store');
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
```
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
125
223
|
中間テーブルはこのようにデータが入っています。
|
126
224
|
|
127
225
|
|id|site_id|store_id|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -53,6 +53,26 @@
|
|
53
53
|
```ここに言語を入力
|
54
54
|
|
55
55
|
StoreController
|
56
|
+
|
57
|
+
<?php
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
namespace App\Http\Controllers;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
use Illuminate\Http\Request;
|
66
|
+
|
67
|
+
use \App\Models\Store;
|
68
|
+
|
69
|
+
use \App\Models\Site;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
class StoreController extends Controller
|
74
|
+
|
75
|
+
{
|
56
76
|
|
57
77
|
|
58
78
|
|