PHP code example of matheusmarnt / scoutify

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

    

matheusmarnt / scoutify example snippets


public function globalSearchTitle(): string      { return $this->title; }
public function globalSearchSubtitle(): ?string  { return $this->author; }
public function globalSearchUrl(): string        { return route('articles.show', $this); }

public static function globalSearchGroup(): string  { return 'Articles'; }
public static function globalSearchLabel(): string  { return 'Articles'; }  // UI chip label
public static function globalSearchIcon(): string   { return 'heroicon-o-document-text'; }
public static function globalSearchColor(): string  { return 'blue'; }

> public static function globalSearchIcon(): string { return 'ri-customer-service-2-fill'; }
> public static function globalSearchIcon(): string { return 'tabler-home'; }
> 

> use Matheusmarnt\Scoutify\Facades\Scoutify;
>
> Scoutify::types()->iconPrefix('ri-');
> 

use Laravel\Scout\Builder;

public function globalSearchBuilder(Builder $builder, string $query): Builder
{
    return $builder->where('published', true);
}

use Matheusmarnt\Scoutify\Authorization\VisibilityRule;
use Matheusmarnt\Scoutify\Contracts\HasGlobalSearchVisibility;

class Article extends Model implements GloballySearchable, HasGlobalSearchVisibility
{
    use Searchable;

    public function globalSearchVisibility(): VisibilityRule
    {
        return VisibilityRule::make()
            ->visibleToGuests()                  // expose to non-authenticated visitors
            ->orWhenAuthenticated()              // OR when authenticated +
                ->policy('view')                 //   passes registered policy
                ->orPermission('view-articles')  //   OR has Spatie permission
                ->orRole('admin')                //   OR has Spatie role
                ->orAttribute('is_active');      //   OR has boolean attribute true
    }
}

'authorization' => [
    'default' => 'secure',          // secure | permissive | gate-only
    'gate_ability' => 'view',       // ability used for policy/gate checks
],

use Matheusmarnt\Scoutify\Contracts\HasGlobalSearchPreview;
use Matheusmarnt\Scoutify\Support\PreviewDto;

class Document extends Model implements GloballySearchable, HasGlobalSearchPreview
{
    use Searchable;

    public function globalSearchPreview(): ?PreviewDto
    {
        // Storage-based file (disk + path)
        return PreviewDto::fromDisk(
            disk: 'documents',
            path: $this->file_path,
            filename: $this->original_name,  // optional; defaults to basename($path)
        );

        // OR: external / CDN URL
        // return PreviewDto::fromUrl('https://cdn.example.com/file.pdf');
    }
}
bash
php artisan scoutify:searchable
bash
php artisan scoutify:searchable --dry-run