Skip to content

Commit 00f3712

Browse files
authored
Fix HasManyThrough relationships (#416)
1 parent da05fbb commit 00f3712

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/SearchableScope.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
66
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
78
use Illuminate\Database\Eloquent\Scope;
89
use Laravel\Scout\Events\ModelsFlushed;
910
use Laravel\Scout\Events\ModelsImported;
@@ -45,5 +46,21 @@ public function extend(EloquentBuilder $builder)
4546
event(new ModelsFlushed($models));
4647
});
4748
});
49+
50+
HasManyThrough::macro('searchable', function ($chunk = null) {
51+
$this->chunkById($chunk ?: config('scout.chunk.searchable', 500), function ($models) {
52+
$models->filter->shouldBeSearchable()->searchable();
53+
54+
event(new ModelsImported($models));
55+
});
56+
});
57+
58+
HasManyThrough::macro('unsearchable', function ($chunk = null) {
59+
$this->chunkById($chunk ?: config('scout.chunk.searchable', 500), function ($models) {
60+
$models->filter->shouldBeSearchable()->searchable();
61+
62+
event(new ModelsImported($models));
63+
});
64+
});
4865
}
4966
}

0 commit comments

Comments
 (0)