mawuekom / laravel-searchable
Laravel package to make easy search on Eloquent model
Requires
- php: ^7.4|^8.0
- illuminate/support: ^8.0|^9.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
README
This package is provided with a service provider and trait to make search on your eloquent model
Installation
You can install the package via composer:
composer require mawuekom/laravel-searchable
Usage
Laravel
Go to config/app.php, and add this in the providers key
'providers' => [ ... Mawuekom\LaravelSearchable\LaravelSearchableServiceProvider::class, ... ]
Lumen
Go to bootstrap/app.php, and add this in the specified key
// Add provider $app->register(Mawuekom\LaravelSearchable\LaravelSearchableServiceProvider::class);
Your model which inherits an eloquent model
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Post extends Model { ... /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'title', 'content' ]; ... }
Use it to make search
use App\Models\Post; Post::whereLike(['title', 'content'], 'Post title');
You can also include Searchable
Trait in your model.
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Mawuekom\LaravelSearchable\Searchable; class Post extends Model { use Searchable; ... }
Once done, you can make your reseach like this
use App\Models\Post; Post::search(['title', 'content'], 'Post title') ->get();
Once done, enjoy it.
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security and Report bug
If you discover any security related issues, please email seddorephraim7@gmail.com or contact me on Twitter @ephraimseddor instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.