dev-master
9999999-dev http://netcore.lvSearch module.
MIT
The Requires
- php >=7.0
by Viktors Ņikiforovs
0.1.x-dev
0.1.9999999.9999999-dev http://netcore.lvSearch module.
MIT
The Requires
- php >=7.0
by Viktors Ņikiforovs
Search module.
This module was made for easy searching in database., (*1)
This module is part of Netcore CMS ecosystem and is only functional in a project that has following packages installed:, (*2)
composer require netcore/module-search
use Illuminate\Database\Eloquent\Model; use Modules\Search\Contracts\SearchableContract; class Article extends Model implements SearchableContract { ... /** * Get the config of search module for building queries. * * @return array */ public function getSearchConfig(): array { return [ // Base table colums 'columns' => [ 'slug', 'author_name', 'author_surname', ], // Add constant wheres if necessary // Helpful for columns like is_active, is_published etc.. 'wheres' => [ 'is_active' => true, ], // Search in relations 'relations' => [ 'translations' => [ 'columns' => [ 'title', 'content', 'intro_text', ], 'wheres' => [ 'locale' => app()->getLocale() // search only in translations for current locale ], // Nested relations supported 'relations' => [...] ] ] ]; } ... }
$page = (int)request('page', 1) ?? 1; $results = search() ->of(\App\Article::class) // set searchable models (multiple allowed) ->setPage($page) // optional - set the current page (1st is by default) ->setRecordsPerPage(15) // optional - set records count per page (20 is by default) ->withLoggedQueries() // optional - enables query logging ->returnAsCollection() // optional - returns collection instead of array ->where(\App\Article::class, 'translations.is_active', true) // add additional where to translations relation ->where(\App\Article::class, 'is_awesome', true) // add additional where to base model ->find('keyword'); dd($results);
Search module.
MIT
Search module.
MIT