PHP code example of areirei / meilisearch-laravel-scout
1. Go to this page and download the library: Download areirei/meilisearch-laravel-scout 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/ */
areirei / meilisearch-laravel-scout example snippets
use Laravel\Scout\Searchable;
class Book extends Model
{
use Searchable;
}
class BookController extends Controller
{
public function store()
{
$book = new Book();
$book->title = 'Pride and Prejudice';
...
$book->save();
}
}
class BookController extends Controller
{
public function search()
{
// MeiliSearch is typo-tolerant:
Book::search('harry pottre')->get();
// Or if you want to get the result from meilisearch:
Book::search('harry pottre')->raw();
}
}
class BookController extends Controller
{
public function destroy($id)
{
// Delete one document
Book::find($id)->delete();
// Delete several documents
Book::destroy([1, 42]);
// Delete all documents /!\
Book::query()->delete();
}
}
use MeiliSearch\Endpoints\Indexes;
class BookController extends Controller
{
public function customSearch()
{
Book::search('prince', function (Indexes $meilisearch, $query, $options) {
$options['filters'] = 'author="Antoine de Saint-Exupéry"';
return $meilisearch->search($query, $options);
})->take(3)->get();
}
}
class BookController extends Controller
{
public function search()
{
Book::search('mustang')->paginate();
// with a limit of items per page:
Book::search('mustang')->paginate(5);
// using meilisearch response:
Book::search('mustang')->paginateRaw();
}
}