Skip to content

Instantly share code, notes, and snippets.

View nunomaduro's full-sized avatar

Nuno Maduro nunomaduro

View GitHub Profile
@nunomaduro
nunomaduro / scout_extended_facade_client.php
Created December 19, 2018 13:46
Scout Extende Facade Client
<?php
use Algolia\ScoutExtended\Facades\Algolia;
$client = Algolia::client();
$apiKeys = $client->listApiKeys();
$indices = $client->listIndices();
$client->copyIndex('indexNameSrc', 'indexNameDest');
$client->moveIndex('indexNameSrc', 'indexNameDest');
@nunomaduro
nunomaduro / scout_extended_settings_file.php
Created December 19, 2018 13:45
Scout Extended Settings File
<?php
return [
/*
|--------------------------------------------------------------------------
| Searchable Attributes
|--------------------------------------------------------------------------
|
| Limits the scope of a search to the attributes listed in this setting. Defining
@nunomaduro
nunomaduro / scout_extended_with.php
Created December 19, 2018 13:38
Scout Extended With
<?php
$articles = Article::search('Star Trek')
->with([
'hitsPerPage' => 30,
'filters' => 'attribute:value',
'typoTolerance' => false,
])->get();
@nunomaduro
nunomaduro / scout_extended_around_lat_lng.php
Created December 19, 2018 13:36
Scout Extended Around Lat Lng
<?php
$articles = Article::search('query')
->aroundLatLng(48.8588536, 2.3125377)
->get();
@nunomaduro
nunomaduro / scout_extended_where_between.php
Created December 19, 2018 13:35
Scout Extended Where Between
<?php
$products = Products::search('Star Trek')
->whereBetween('price', [100, 200])
->get();
@nunomaduro
nunomaduro / scout_extended_where.php
Created December 19, 2018 13:30
Scout Extended Where
<?php
$articles = Article::search('Star Trek')->where('views', '>', 100)->get();
$articles = Article::search('Star Trek')->where('created_at', '>=', now()->subDays(7))->get();
$articles = Article::search('Star Trek')->where('views', 100)->get(); // views = 100
@nunomaduro
nunomaduro / searching_aggregators.php
Created December 19, 2018 12:39
Searching aggregators
<?php
$models = App\Search\News::search('Star Trek')->get();
echo get_class($models[0]); // "App\Article"
echo get_class($models[1]); // "App\Comment"
$results = App\Search\News::search('Star Trek')->raw();
/*
{
"hits":[
@nunomaduro
nunomaduro / AppServiceProvider.php
Created December 19, 2018 12:33
Register Aggregator
<?php
namespace App\Providers;
use App\Search\News;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
@nunomaduro
nunomaduro / News.php
Created December 19, 2018 12:32
Aggregator example
<?php
namespace App\Search;
use Algolia\ScoutExtended\Searchable\Aggregator;
class News extends Aggregator
{
/**
* The names of the models that should be aggregated.
@nunomaduro
nunomaduro / box.json
Created September 16, 2018 15:42
Laravel Zero - box.json
{
"chmod": "0755",
"directories": [
"app",
"bootstrap",
"config",
"vendor"
],
"files": [
"composer.json"