PHP code example of archy-bold / eloquent-searchable

1. Go to this page and download the library: Download archy-bold/eloquent-searchable 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/ */

    

archy-bold / eloquent-searchable example snippets


	'providers' => [

		// ...

		'ArchyBold\EloquentSearchable\SearchServiceProvider',

	];

use ArchyBold\EloquentSearchable\SearchableModel;
use ArchyBold\EloquentSearchable\SearchableTrait;

class User extends Model implements SearchableModel {

	use SearchableTrait;

	protected $searchable = [
		'columns' => [
			'name', // Reference columns that should be searchable here
			'country.name', // You can reference columns through relationships too.
		],
	];

	'models' => [
		'users' => 'App\User',
	],

$user = new User;
$results = $user->search("query string");

$search = app('ArchyBold\EloquentSearchable\SearchProvider');

use ArchyBold\EloquentSearchable\SearchProvider;

class UserController extends Controller {

    /**
     * The search provider instance.
     */
    protected $search;

    /**
     * Create a new controller instance.
     *
     * @param  SearchProvider  $search
     * @return void
     */
    public function __construct(SearchProvider $search)
    {
        $this->search = $search;
    }

    // Or with methods injection ...

    public function search(SearchProvider $search)
    {
    	// Use search instance
    }

}

	$results = $search->searchAll("query string");
	dd($results['users']);
bash
$ php artisan vendor:publish