PHP code example of openplain / laravel-lightsearch
1. Go to this page and download the library: Download openplain/laravel-lightsearch 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/ */
openplain / laravel-lightsearch example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
class Post extends Model
{
use Searchable;
protected $fillable = ['title', 'excerpt', 'content'];
public function toSearchableArray(): array
{
return [
'title' => $this->title,
'excerpt' => $this->excerpt,
'content' => $this->content,
];
}
}
// Automatically finds "Laravel" even with typo
Post::search('laravle')->get();
// Automatically finds "Tórshavn" without accents
Address::search('Torshavn')->get();