Laravel Pro Tips

Laravel Pro Tips

Share this post

Laravel Pro Tips
Laravel Pro Tips
Searching Across Different Models in Laravel

Searching Across Different Models in Laravel

Looking to search across multiple Eloquent models in Laravel, such as posts, videos, and courses? Laravel offers several ways to achieve this, be it through its in-built features or external packages.

Laravel Pro Tips's avatar
Laravel Pro Tips
Oct 27, 2023
∙ Paid

Share this post

Laravel Pro Tips
Laravel Pro Tips
Searching Across Different Models in Laravel
Share

magnifying glass on white table
Photo by Markus Winkler on Unsplash

Our Starting Point:

We've got three basic database tables:

  • Posts

  • Videos

  • Courses

Each of these tables corresponds to an Eloquent model. Our goal? To seamlessly search across these tables and pull combined results.


The Basics: Searching Across Three Models

Let's dive into the simplest method for searching across multiple models in Laravel. It might not be the fanciest, but it gets the job done.

Start with fetching the keyword from your request:

$keyword = request('keyword');

Next, run individual queries on each model to gather your results:

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2025 Laravel Pro Tips
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share