PHP code example of flyingapesinc / deepsearch

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

    

flyingapesinc / deepsearch example snippets


FlyingApesInc\DeepSearch\ServiceProvider::class,

'DeepSearch' => FlyingApesInc\DeepSearch\Facade::class,

use FlyingApesInc\DeepSearch\Traits\DeepSearchable;

class Model extends Eloquent {

    use DeepSearchable;

    ...
}

$posts = Post::deepSearch($userInput, ['title'], [
    'comments' => 'comment',
    'comments.user' => ['name', 'lastname']
])->get();

$searchSchema = [
    'fields' => ['title'], // Fields where you want to search in the main model
    'relationships' => [ // Relationships, if any
        [
            'relationship' => 'comments', // Here you put name of the relationship
            'fields' => 'comment', // And here the fields where you want to search in the related table
        ],
        [
            'relationship' => 'comments.user', // Use dot notation for inner relations
            'fields' => ['name', 'lastname'],
        ]
    ]
];

$search = DeepSearch::find($userInput, App\Post::query(), $searchSchema)->where('active', 1)->paginate(10);