PHP code example of denismitr / search
1. Go to this page and download the library: Download denismitr/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/ */
denismitr / search example snippets
namespace App\Queries;
use App\Post;
use Denismitr\Search\Searchable;
use Denismitr\Search\Searchers\SimpleSearcher;
class TitleSearcher extends SimpleSearcher implements Searchable
{
//Here you specify a Eloquent model class which you search and the collection of which you whant to get
//as a return of the search
protected $model = Post::class;
//Here you specify the field you in which to search
protected $searchField = 'title';
}
namespace App\Queries;
use App\Post;
use App\Topic;
use Denismitr\Search\Searchable;
use Denismitr\Search\Searchers\RelationalSearcher;
class TopicNameSearcher extends RelationalSearcher implements Searchable
{
protected $model = Post::class;
protected $searchField = 'name';
//Here you specify the Eloquent relational methods (that return hasMany or belongstoMany)
protected $relation = 'topics';
}