We've recently built Upserver.online, a sophisticated health checker for Laravel applications with support for databases, queues, broadcasting, mail, caching, security checks and it even monitors your uptime, DNS records, SSL certificates and mixed content. Create an account and follow us on Twitter!

Search through multiple Eloquent models with our latest Laravel package

July 14, 2020

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')

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')

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?

  • Search through one or more Eloquent models.
  • Support for cross-model pagination.
  • Search through single or multiple columns.
  • Use constraints and scoped queries.
  • Eager load relationships for each model.
  • In-database sorting of the combined result.
  • Zero third-party dependencies.
  • PHP 7.4 only, Laravel 6.0 and 7.0 supported, MySQL 5.7+ required.

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