• Reading time ~ 1 min
  • 10.09.2022

Laravel Cross-Eloquent Search is a package to search through multiple Eloquent models. This package supports sorting, pagination, scoped queries, eager load relationships, and searching through single or multiple columns:

// Returns \Illuminate\Database\Eloquent\Collection
    ->add(Post::class, 'title')
    ->add(Video::class, 'title')
// Add multiple models at once
    [Post::class, 'title'],
    [Video::class, 'title'],

Often, you'll want to paginate results, and this package makes doing so a cinch:

Search::add(Post::class, 'title')
    ->add(Video::class, 'title')
    // or
    ->paginate(perPage: 15, pageName: 'page', page: = 1)

The readme has tons of information about using this package that I'd recommend checking out:

  • Search through one or more Eloquent models
  • Support for cross-model pagination
  • Search through single or multiple columns
  • Order by (cross-model) columns or by relevance
  • Use constraints and scoped queries
  • Eager load relationships for each model
  • In-database sorting of the combined result
  • Zero third-party dependencies

You can learn more about this package, get full installation instructions, and view the source code on GitHub. The author of this package also wrote a blog post that goes into more detail about using this package.


No comments yet
Yurij Finiv

Yurij Finiv

Full stack


Professional Fullstack developer with experience in website development and desktop development. I have experience with various tools and technologies such as Bootstrap, Tailwind, HTML5, CSS3, PUG, JS, AlpineJs, jQuery, PHP, MODX, Laravel, NodeJS, Git, Docker, hQuery, Guzzle, Livewire, Blade, Twig, Fenom, and Smarty. I have experience in website development using Symfony, MODX and Laravel. Experie...

About author CrazyBoy49z
Ukraine, Lutsk