Skip to content

Commit 53130b2

Browse files
[9.x] Added soft deleted to Meilisearch (OOTB included) (#672)
* Added soft deleted to Meilisearch * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent 2bc384e commit 53130b2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Console/IndexCommand.php

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

55
use Exception;
66
use Illuminate\Console\Command;
7+
use Illuminate\Database\Eloquent\SoftDeletes;
78
use Illuminate\Support\Str;
89
use Laravel\Scout\EngineManager;
910

@@ -59,6 +60,12 @@ public function handle(EngineManager $manager)
5960
?? config('scout.'.$driver.'.index-settings.'.$class)
6061
?? [];
6162

63+
if (isset($model) &&
64+
config('scout.soft_delete', false) &&
65+
in_array(SoftDeletes::class, class_uses_recursive($model))) {
66+
$settings['filterableAttributes'][] = '__soft_deleted';
67+
}
68+
6269
if ($settings) {
6370
$engine->updateIndexSettings($name, $settings);
6471
}

src/Console/SyncIndexSettingsCommand.php

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

55
use Exception;
66
use Illuminate\Console\Command;
7+
use Illuminate\Database\Eloquent\SoftDeletes;
78
use Illuminate\Support\Str;
89
use Laravel\Scout\EngineManager;
910

@@ -44,6 +45,22 @@ public function handle(EngineManager $manager)
4445

4546
if (count($indexes)) {
4647
foreach ($indexes as $name => $settings) {
48+
if (! is_array($settings)) {
49+
$name = $settings;
50+
51+
$settings = [];
52+
}
53+
54+
if (class_exists($name)) {
55+
$model = new $name;
56+
}
57+
58+
if (isset($model) &&
59+
config('scout.soft_delete', false) &&
60+
in_array(SoftDeletes::class, class_uses_recursive($model))) {
61+
$settings['filterableAttributes'][] = '__soft_deleted';
62+
}
63+
4764
$engine->updateIndexSettings($indexName = $this->indexName($name), $settings);
4865

4966
$this->info('Settings for the ['.$indexName.'] index synced successfully.');

0 commit comments

Comments
 (0)