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(),
]);
}
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';
}