Protone Media logo

Search through multiple Eloquent models with our latest Laravel package

There are many ways to add search functionality to your Laravel project. You can use the Query Builder, use the official Scout package to integrate with Algolia or use a third-party package like Spatie's laravel-searchable. Today we're introducing a new package to perform cross model, in-database searching. Here's a quick example how to perform a search query with our package:

$results = Search::add(Post::class, 'title')
    ->add(Video::class, 'title')
    ->get('howto');

We've made it really versitile and developer friendly. The example above is simple, but you can do really advanced searches as well:

$results = Search::add(Post::where('views', '>', 500), 'title', 'published_at')
    ->add(Video::with('tags')->published(), ['title', 'subtitle'], 'released_at')
    ->startWithWildcard()
    ->orderByDesc()
    ->paginate(25)
    ->get('howto');

We currently only support MySQL 5.7+, but we might add support for other drivers as well. So what can you expect from this package?

The GitHub repository contains extensive documentation of all features. Follow me on Twitter for Laravel tips and package updates!

Related posts

Want to stay up-to-date on Laravel news and packages?

Pascal Baljet on Twitter

Follow me on Twitter: @pascalbaljet

Pascal Baljet on Twitter

Subscribe to my YouTube channel

© 2013-2024 Protone Media B.V. Hosted with Eddy Server Management.