diff --git a/app/Console/Commands/CreateScoutIndexes.php b/app/Console/Commands/CreateScoutIndexes.php new file mode 100644 index 00000000..bedc0b1f --- /dev/null +++ b/app/Console/Commands/CreateScoutIndexes.php @@ -0,0 +1,46 @@ +call('scout:delete-all-indexes'); + + collect(File::allFiles(app_path('Models'))) + ->map(fn ($item) => 'App\\Models\\'.$item->getBasename('.php')) + ->filter(fn ($item) => in_array(\Laravel\Scout\Searchable::class, class_uses($item))) + ->each(function ($item) { + $this->call('scout:index', [ + 'name' => (new $item())->searchableAs(), + ]); + + $this->call('scout:import', [ + 'model' => $item, + ]); + }); + + $this->call('scout:sync-index-settings'); + } +} diff --git a/create_scout_indexes.sh b/create_scout_indexes.sh new file mode 100755 index 00000000..351ebe8c --- /dev/null +++ b/create_scout_indexes.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +./sail artisan app:create-scout-indexes