回答編集履歴
2
修正
answer
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
```php
|
8
8
|
class Post extends Model
|
9
9
|
{
|
10
|
-
public function
|
10
|
+
public function scopeWithComments(Builder $builder)
|
11
11
|
{
|
12
12
|
return $builder->with(['comments']);
|
13
13
|
}
|
1
修正
answer
CHANGED
@@ -2,4 +2,16 @@
|
|
2
2
|
|
3
3
|
とはいえ、コントローラには書かないと思います。
|
4
4
|
|
5
|
-
model に scope で実装するかな…
|
5
|
+
model に scope で実装するかな…
|
6
|
+
|
7
|
+
```php
|
8
|
+
class Post extends Model
|
9
|
+
{
|
10
|
+
public function scopeWith(Builder $builder)
|
11
|
+
{
|
12
|
+
return $builder->with(['comments']);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
```
|
16
|
+
|
17
|
+
と思ったけど、paginate() は Collection 返すから、スコープでは実装できませんね。
|