Pretty much every app needs decent search engine. Nowadays specialized engines like ElasticSearch are getting more attention, but if you don't want or need such specilized service, you can implement your own Eloquent search.
That said, let me introduce you to the fastest, most reliable and flexible searchable feature for eloquent models out there Eloquence searchable
A quick usage example:
class User extends Eloquent {
use Eloquence; // Sofa\Eloquence\Eloquence trait
// OPTIONALLY define default searchable columns
protected $searchableColumns = ['name', 'email'];
}
// basic usage, fulltext search for '*jarek*' or '*sofa*' through defined columns
>>> User::search('jarek sofa')->get();
// exact search for 'jarek tkaczyk' through defined columns
>>> User::search('"jarek tkaczyk"', false)->first();
// wildcard search for 'jarek*' or '*czyk' thru provided columns with weighted score
>>> User::search(['jarek*', '*czyk'], ['name' => 10, 'email' => 5], false)->get();
// fulltext search on multiple tables (joined automatically using dot nested relations)
>>> User::search('foo bar', ['name', 'posts.title', 'posts.categories.name', 'profile.address.city'])->get();
Read more in the linked wiki, ask if there's anything you'd like to know, and have fun with the package!
This looks awesome i have to say, BUT, why L5+?
Many of us still use L4 on a lot of older projects, does it use L5+ specific stuff? Cant it work on L4 somehow?
Thanks!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community