spekt08/laravel-search is a Laravel package for a laravel package for advanced search functionality.
It currently has 0 GitHub stars and 3 downloads on Packagist.
Install it with composer require spekt08/laravel-search.
Discover more Laravel packages by spekt08
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel package to provide advanced, modular search functionality using customizable search cases.
Install the package via Composer:
composer require spekt08/laravel-search:dev-main
Publish the configuration file (if applicable):
php artisan vendor:publish --provider="spekt08\Search\SearchServiceProvider" --tag=config
The SearchService requires a model to operate on. You can instantiate it as follows:
use spekt08\Search\SearchService;
$service = app(SearchService::class, [
'model' => \App\Models\User::class
]);
Call the search method with the desired query parameters. For example:
$queries = [
'name' => 'John', // Filter users by name
'created_at' => '2025-01-01', // Filter by creation date
'order' => 'asc', // Sort in ascending order
];
$result = $service->search($queries);
This will return a paginated result set.
If you are using Laravel API Resources, you can pass the resource class as the second parameter of the search method:
use App\Http\Resources\UserResource;
$result = $service->search($queries, UserResource::class);
This will transform each result using the provided resource.
The package includes three default search cases:
created_at).You can add custom cases by implementing the SearchCaseInterface:
use spekt08\Search\Cases\SearchCaseInterface;
use Illuminate\Database\Eloquent\Builder;
class CustomCase implements SearchCaseInterface
{
public function searchQuery(Builder $query, array $params): Builder
{
if (isset($params['custom_filter'])) {
$query->where('custom_column', $params['custom_filter']);
}
return $query;
}
}
Add the custom case to the service:
$customCase = new CustomCase();
$service->add($customCase);
If the package includes a config/search.php file, you can customize the default behavior, such as:
not_columns).date_columns).$service = app(SearchService::class, ['model' => \App\Models\Post::class]);
$queries = [
'title' => 'Laravel',
'author' => 'Taylor',
'order' => 'desc',
'callbacks' => [
function ($query) {
$query->where('status', 'published');
},
],
];
$result = $service->search($queries, \App\Http\Resources\PostResource::class);
Feel free to open issues or submit pull requests for new features, bug fixes, or improvements.
This package is open-sourced software licensed under the MIT license.