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();
    }
}
bash
composer 
bash
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
php artisan vendor:publish --provider="Meilisearch\Scout\MeilisearchServiceProvider" --tag="config"
bash
// Create an index
php artisan scout:index books
// Create an index and give the primary-key
php artisan scout:index books --key book_id
bash
php artisan scout:flush "App\Book"
bash
php artisan scout:index -d books
bash
// Get displayed
php artisan scout:display books
// Edit displayed
php artisan scout:display books book_id book_name
// Reset displayed
php artisan scout:display books --reset
bash
// Get distinct
php artisan scout:distinct books
// Edit distinct
php artisan scout:distinct books book_id
// Reset distinct
php artisan scout:distinct books --reset
bash
// Get filterable
php artisan scout:filter books
// Edit filterable
php artisan scout:filter books book_id book_name
// Reset filterable
php artisan scout:filter books --reset
bash
// Get ranking
php artisan scout:ranking books
// Edit ranking
php artisan scout:ranking books book_id book_name
// Reset ranking
php artisan scout:ranking books --reset
bash
// Get searchable
php artisan scout:search books
// Edit searchable
php artisan scout:search books book_id book_name
// Reset searchable
php artisan scout:search books --reset
bash
// Get sortable
php artisan scout:sort books
// Edit sortable
php artisan scout:sort books name
// Reset sortable
php artisan scout:sort books --reset