Put SearchTrait.php
in app
directory. Then use SearchTrait
in your model, like so
use App\SearchTrait;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
use SearchTrait; // Add this
// Optional properties
protected $search = ['title', 'content'];
}
Somewhere in your controller
$keyword = 'lorem';
// Match any fields
Article::search($keyword)->paginate();
// Match all fields
Article::search($keyword, true)->paginate();
Thanks :)