PHP code example of muhammad-nawlo / filament-scout-manager

1. Go to this page and download the library: Download muhammad-nawlo/filament-scout-manager 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/ */

    

muhammad-nawlo / filament-scout-manager example snippets


use MuhammadNawlo\FilamentScoutManager\FilamentScoutManagerPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugins([
            FilamentScoutManagerPlugin::make(),
        ]);
}

return [
    'log_searches' => true,
    'log_retention_days' => 30,
    'enable_synonyms' => true,
    'models' => [
        // 'App\\Other\\Model' => [],
    ],
];

use Illuminate\Database\Eloquent\Model;
use MuhammadNawlo\FilamentScoutManager\Concerns\SearchableWithScoutManagerConfig;

class Product extends Model
{
    use SearchableWithScoutManagerConfig;
}

use App\Models\Product;

Product::withoutSyncingToSearch(function () {
    Product::where('status', 'draft')->update(['status' => 'published']);
    // ... other bulk operations
});

public function shouldBeSearchable(): bool
{
    return $this->is_published;
}

use Laravel\Scout\Attributes\SearchUsingFullText;
use Laravel\Scout\Attributes\SearchUsingPrefix;

#[SearchUsingFullText(['title', 'description'])]
#[SearchUsingPrefix(['sku'])]
public function toSearchableArray(): array
{
    return [
        'title' => $this->title,
        'description' => $this->description,
        'sku' => $this->sku,
    ];
}

$table->fullText(['title', 'description']);

use Illuminate\Database\Eloquent\Builder;

protected function makeAllSearchableUsing(Builder $query): Builder
{
    return $query->with(['category', 'tags']);
}

use Illuminate\Database\Eloquent\Collection;

public function makeSearchableUsing(Collection $models): Collection
{
    return $models->load('author');
}

public function getScoutKey()
{
    return $this->email;
}

public function getScoutKeyName()
{
    return 'email';
}

Post::search('laravel')
    ->options([
        'query_by' => 'title, description',
        'filter_by' => 'published:=true',
    ])
    ->get();
bash
php artisan filament-scout-manager:install
bash
php artisan vendor:publish --tag="filament-scout-manager-config"
php artisan vendor:publish --tag="filament-scout-manager-migrations"
php artisan migrate
css
@source '../../../../vendor/muhammad-nawlo/filament-scout-manager/resources/**/*.blade.php';