PHP code example of clarkwinkelmann / flarum-ext-scout

1. Go to this page and download the library: Download clarkwinkelmann/flarum-ext-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/ */

    

clarkwinkelmann / flarum-ext-scout example snippets




use ClarkWinkelmann\Scout\Extend\Scout;
use Acme\Event\SubtitleRenamed;

return [
    (new Scout(Discussion::class))
        ->listenSaved(SubtitleRenamed::class, function (SubtitleRenamed $event) {
            return $event->discussion;
        })
        ->attributes(function (Discussion $discussion): array {
            return [
                'subtitle' => $discussion->subtitle,
            ];
        }),
];



use ClarkWinkelmann\Scout\ScoutModelWrapper;
use Flarum\Discussion\Discussion;

/**
 * @var Discussion $discussion
 */
$discussion->subtitle = 'New value';
$discussion->save();

(new ScoutModelWrapper($discussion))->scoutObserverSaved();



use ClarkWinkelmann\Scout\ScoutStatic;
use Flarum\User\User;

$builder = ScoutStatic::makeBuilder(User::class, 'Hello World');

$ids = $builder->keys();

$users = User::newQuery()
    ->whereVisibleTo($actor)
    ->whereIn('id', $ids)
    ->orderByRaw('FIELD(id' . str_repeat(', ?', count($ids)) . ')', $ids)
    ->limit(10)
    ->get();