Skip to content

Instantly share code, notes, and snippets.

View nunomaduro's full-sized avatar

Nuno Maduro nunomaduro

View GitHub Profile
@nunomaduro
nunomaduro / laravel-console-task.php
Created December 15, 2017 18:32
Laravel Console Task usage example
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class LaravelInstallCommand extends Command
{
/**
* Execute the console command.
@nunomaduro
nunomaduro / LaravelConsoleTaskServiceProvider.php
Created December 16, 2017 20:01
LaravelConsoleTaskServiceProvider.php
<?php
declare(strict_types=1);
/**
* This file is part of Laravel Console Task.
*
* (c) Nuno Maduro <enunomaduro@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
<?php
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
use Illuminate\Support\Facades\Storage;
class BackupCommand extends Command
{
@nunomaduro
nunomaduro / box.json
Created September 16, 2018 15:42
Laravel Zero - box.json
{
"chmod": "0755",
"directories": [
"app",
"bootstrap",
"config",
"vendor"
],
"files": [
"composer.json"
@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 / 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 / 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 / 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 / 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_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();