jeroen-g/explorer
Laravel-friendly, fluent API for exploring and filtering directories and files. Chain common queries (name, extension, size, modified time), include/exclude patterns, sort and paginate results, and iterate over matches with clean, expressive code.
Installation:
composer require jeroen-g/explorer
php artisan vendor:publish --tag=explorer.config
Update config/scout.php to set 'driver' => 'elastic'.
Configure Elasticsearch:
docker-compose.yml).config/explorer.php:
'indexes' => [
'posts_index' => [
'properties' => [
'id' => 'keyword',
'title' => 'text',
],
],
],
First Use Case:
php artisan scout:import "App\Models\Post"
$results = App\Models\Post::search('query')->get();
Index Management:
scout:import for initial setup or elastic:update for aliased indexes.scout:delete-index to drop an index.elastic:search for ad-hoc queries:
php artisan elastic:search "App\Models\Post" "query" --fields=title,body
Model Integration:
toSearchableArray():
public function toSearchableArray()
{
return [
'title' => $this->title,
'body' => $this->body,
];
}
Advanced Queries:
$results = Post::search('query')
->where('published_at', '>', now()->subYear())
->orderBy('views', 'desc')
->get();
Pagination:
$results = Post::search('query')->paginate(10);
elastic:update for zero-downtime index rotations.Post::search('query')->orderBy('created_at', 'desc');
$results = Post::search('query')->withAggregations(['tags']);
Mapping Conflicts:
config/explorer.php to enforce schema consistency.Connection Issues:
localhost:9200).ElasticEngine::debug()->json() to inspect raw queries.Performance:
ignore_above.text for searchable fields and keyword for exact matches.Aliases:
elastic:update after modifying indices.EXPLORER_ELASTIC_LOGGER_ENABLED=true and configure in explorer.php:
'logger' => \Illuminate\Support\Facades\Log::channel('daily'),
$this->instance(ElasticClientFactory::class, ElasticClientFactory::fake($fakeResponse));
Custom Mappings:
config/explorer.php for complex types (e.g., nested objects):
'properties' => [
'tags' => [
'type' => 'nested',
'properties' => ['name' => 'keyword'],
],
],
Preprocessing:
toSearchableArray() to transform data before indexing:
public function toSearchableArray()
{
return [
'title' => strtolower($this->title),
];
}
Advanced Queries:
QueryBuilder for custom DSL:
$query = Post::search('query')->query(function ($q) {
return $q->bool()->must([
'match' => ['title' => 'search term'],
]);
});
ssl.verify is configured (default: true)..env:
EXPLORER_HOST=elasticsearch.example.com
EXPLORER_PORT=9200
How can I help you explore Laravel packages today?