質問編集履歴
1
試したことを追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -80,14 +80,13 @@
|
|
80
80
|
protected $table = 'users';
|
81
81
|
|
82
82
|
/**
|
83
|
-
* Timecards
|
83
|
+
* Timecardsリレーション
|
84
84
|
* 1対多
|
85
85
|
*/
|
86
86
|
public function timecards()
|
87
87
|
{
|
88
88
|
return $this->hasMany(Timecard::class);
|
89
89
|
}
|
90
|
-
|
91
90
|
}
|
92
91
|
```
|
93
92
|
■コントローラー
|
@@ -128,5 +127,28 @@
|
|
128
127
|
@endforeach
|
129
128
|
</tbody>
|
130
129
|
```
|
130
|
+
### 試したこと
|
131
|
+
1: Userモデルにperformancesテーブルへのリレーションを追加
|
132
|
+
```
|
133
|
+
public function performances()
|
134
|
+
{
|
135
|
+
return $this->hasManyThrough(Performance::class, Timecard::class);
|
136
|
+
}
|
137
|
+
```
|
138
|
+
2: Performanceモデルにusersテーブルへのリレーションを追加
|
139
|
+
```
|
140
|
+
public function user()
|
141
|
+
{
|
142
|
+
return $this->belongsTo(User::class);
|
143
|
+
}
|
144
|
+
|
145
|
+
```
|
146
|
+
|
147
|
+
```
|
148
|
+
public function user()
|
149
|
+
{
|
150
|
+
return $this->belongsToMany(User::class);
|
151
|
+
}
|
152
|
+
```
|
131
153
|
### 調べたこと
|
132
154
|
hasManyThroughのように中間テーブルを経由してリレーション出来る、belongsToThroughのようなものがあればと考えたのですが、存在しないようです。
|