PHP code example of dzava / global-search

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

    

dzava / global-search example snippets



class User extends Model {
	public function searchableFields() {
    	return ['name'];
    }
}

class Post extends Model {
	public function searchableFields() {
    	return ['title'];
    }
}

use Dzava\GlobalSearch\GlobalSearch;

$results = (new GlobalSearch())->withModels([User::class, Post::class])->search('Doe');

//  [
//      'users' => [
//          ['name' => 'John Doe', 'email' => '[email protected]'],
//          ['name' => 'Jane Doe', 'email' => '[email protected]']
//  ],
//      'posts'  => [
//          ['title' => 'Who is John Doe', 'slug' => 'who-is-john-doe'
//      ]
//  ]

GlobalSearch::registerModels(['Accounts' => User::class, Post::class]);
bash
php artisan vendor:publish --tag=config --provider="Dzava\GlobalSearch\GlobalSearchServiceProvider"