hepplerdotnet / fulltextsearch
实现 Laravel Eloquent 中全文搜索的特质
2.0.3
2021-04-01 08:56 UTC
Requires
- php: >=8.0.0
- laravel/framework: >=8.0.0
This package is auto-updated.
Last update: 2024-08-29 05:31:31 UTC
README
PHP 特质,用于在 Eloquent 模型中实现 MySQL 全文搜索
安装与使用
首先,通过 Composer 拉取此包。
运行 composer require hepplerdotnet/fulltextsearch
然后在您的 Eloquent 模型中包含该特质以实现全文搜索。
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use HepplerDotNet\FullTextSearch\FullTextSearch; class FooBar extends Model { use FullTextSearch; /* Table Fields which should be searchable */ protected $searchable = [ 'title', 'description' ]; ... }
为字段创建 MySQL 全文索引。
将其用作模型上的作用域。
$result = FooBar::search('Foo')->get();