PHP code example of ccennis / larelastic
1. Go to this page and download the library: Download ccennis/larelastic 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/ */
ccennis / larelastic example snippets
Larelastic\Elastic\Providers\ElasticServiceProvider::class
'Elastic' => Larelastic\Elastic\Facades\Elastic::class
php artisan vendor:publish
ELASTICSEARCH_HOST=http://elastic:9200
ELASTICSEARCH_PORT=9200
SCOUT_DRIVER=elastic
SCOUT_ELASTIC_HOST=http://elastic:9200
artisan scout:import "App\Models\Tattoo"
$response = Tattoo::search()->where('name', 'mold')->get();
$response = Tattoo::search()->where('name', '=', 'mold')->get();
$response = Tattoo::search()->orWhere(['name', '=', 'mold'],['name', '=', 'Element'])->get();
$response = Tattoo::search()->orWhere(function($query, $boolean){
$query->where('name', '=','Mold', $boolean)
->where('model', '=','test', $boolean);
return $query;
})->orWhere(function($query, $boolean){
$query->where('name', '=','element', $boolean)
->where('model', '=','test', $boolean);
return $query;
})->get();
$response = Tattoo::search()->whereMulti(['name', 'model'],'=','Mold')->get();
$response = Tattoo::search()->whereMulti(['name', 'model'],'=','Mold', 'best_fields')->get();
$response = Tattoo::search()->whereMulti(['name', 'model'],'=','Mold')->paginate(20);
$response = Tattoo::search()->where('name', 'mold')
sort->('name','desc')->get()
$response = Tattoo::search()->where('name', 'mold')
sort->('name', 'desc', 'keyword')->get()
$response = Tattoo::search()->where('name', 'mold')
->rollup('card_color')->get();
php artisan make:index-configurator TattooIndexConfigurator
php artisan make:searchable-model Product --index-configurator=TattooIndexConfigurator
php artisan elastic:create-index "App\Models\Tattoo"
php artisan elastic:update-mapping "App\\Models\MyModel"
php artisan elastic:update-index "App\Models\MyModelConfigurator"
php artisan elastic:drop-index "App\Models\MyModel"
public function searchableQuery()
{
return $self->newQuery();
}