ditscheri / eloquent-search
This is my package EloquentSearch
Fund package maintenance!
ditscheri
Requires
- php: ^8.0
- illuminate/contracts: ^8.37|^9.0|^10.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^5.10|^6.0|^7.0
- nunomaduro/larastan: ^1.0.3|^2.0.1
- orchestra/testbench: ^6.15|^7.0|^8.0
- pestphp/pest: ^1.21|^2.0
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-10-24 15:11:47 UTC
README
PACKAGE IN DEVELOPMENT, DO NOT USE YET
Eloquent Search
This package lets you perform fast and local searches on your Eloquent Models. You can search foreign columns of related models too.
The approach is based on a gist by Jonathan Reinink (https://gist.github.com/reinink/28bd174087e929ffa1f150e3fe8ffbfa).
Installation
You can install the package via composer:
composer require ditscheri/eloquent-search
Usage
class Podcast extends Model { use \Ditscheri\EloquentSearch\Searchable; /** * The attributes that are searchable. * * @var string[] */ protected array $searchable = [ 'title', // make sure to add proper indexes to each of these columns 'description', 'author.first_name', 'author.last_name', 'comments.message', 'series.title', 'series.tags.name', ]; public function author() { return $this->belongsTo(User::class); } public function comments() { return $this->hasMany(Comment::class); } public function series() { return $this->belongsTo(Series::class); } } class PodcastController { public function index(Request $request) { return Podcast::search($request->input('q', null))->paginate(); } }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.