1. Go to this page and download the library: Download xiaolin/laravel-es library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
class Article extends Model
{
use Searchable;
/**
* 索引的字段
*
* @return array
*/
public function toSearchableArray()
{
return $this->only('id', 'title', 'content');
}
}
use App\Models\Article;
Route::get('search', function () {
// 为查看方便都转成数组
dump(Article::all()->toArray());
dump(Article::search('功能齐全的搜索引擎')->get()->toArray());
});