PHP code example of mabadir / elastic-laravel

1. Go to this page and download the library: Download mabadir/elastic-laravel 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/ */

    

mabadir / elastic-laravel example snippets


ElasticSearcher::search('simple term');

$user = App\User::first();
ElasticSearcher::search('Simple Term', $user);

ElasticSearcher::search(['name' => 'First Name']);

$user = App\User::first();
ElasticSearcher::search(['name' => 'First Name'], $user);

$params = [
            'body' => [
                'query' => [
                    'match' => [
                        '_all' => 'Simple Term'
                    ]
                ]
            ]
        ];
ElasticSearcher::advanced($params);

$user = User::first();
$params = [
            'body' => [
                'query' => [
                    'match' => [
                        '_all' => 'Simple Term'
                    ]
                ]
            ]
        ];
ElasticSearcher::advanced($params, $user);

ElasticSearcher::search(['name' => 'First Name'], User::class);

namespace App\Console\Commands;

use Illuminate\Console\Command;
use MAbadir\ElasticLaravel\Console\IndexInitializationTrait;

class IndexIntializationCommand extends Command
{
    use IndexInitializationTrait;

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'es:initialize';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Initialize ElasticSearch Index';
    
    /**
     * Parameters array
     * 
     * @var array
     */
    protected $params = [
        //Custom Settings
    ];
}

 php
'providers' => [
//Other providers
    MAbadir\ElasticLaravel\ElasticLaravelServiceProvider::class,
],
 bash
$ php artisan vendor:publish
 php
'aliases' => [
    //Other Facades
   'ElasticSearcher' => MAbadir\ElasticLaravel\ElasticSearcher::class,
],

$ php artisan es:init

$ php artisan make:command IndexIntializationCommand