This package is a macro service provider to make search on your eloquent model
You can install the package via composer:
composer require mawuekom/laravel-macro-search
Go to config/app.php, and add this in the providers key
'providers' => [
...
Mawuekom\MacroSearch\MacroSearchServiceProvider::class,
...
]
Go to bootstrap/app.php, and add this in the specified key
// Add provider
$app->register(Mawuekom\MacroSearch\MacroSearchServiceProvider::class);
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'posts';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'post_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'title',
'content'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [];
}
use App\Models\Post;
Post::whereLike(['title', 'content'], 'Post title');
Contact me on Twitter @ephraimseddor
The MIT License (MIT). Please see License File for more information.