This package is provided with a service provider and trait to make search on your eloquent model
You can install the package via composer:
composer require mawuekom/laravel-searchable
Go to config/app.php, and add this in the providers key
'providers' => [
...
Mawuekom\LaravelSearchable\LaravelSearchableServiceProvider::class,
...
]
Go to bootstrap/app.php, and add this in the specified key
// Add provider
$app->register(Mawuekom\LaravelSearchable\LaravelSearchableServiceProvider::class);
<?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 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();
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email seddorephraim7@gmail.com or contact me on Twitter @ephraimseddor instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.