Using Eloquent ORM in Laravel to perform search of database using LIKE
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Whether you're building a massive application or just starting out, being able to search and find the right data efficiently is crucial. In this blog post, we'll explore using Eloquent Object-Relational Mapping (ORM) in your Laravel project for LIKE searches. We'll discuss best practices and provide code examples to help you get started.
What is Eloquent ORM?
Eloquent Object-Relational Mapping, or Eloquent for short, is a component of the Laravel PHP framework that provides an elegant interface for managing database tables and their relationships. It simplifies working with databases by abstracting out repetitive tasks like making queries and defining relationships between models.Performing LIKE Queries Using Eloquent
To perform a search using LIKE, you must use the 'where' method provided by Eloquent ORM. This enables you to construct complex SQL statements with ease. Let's say we have a table named "users" and want to find users whose names start with "john". Here's how you can do it:php
User::where('name', 'like', 'John%')->get();php
User::where('name', 'like', 'John%')->get();php
User::where('name', 'like', 'John%')
->orWhere('city', '=', 'Manchester')
->orWhere(function($query) {
$query->where('country', '=', 'England')
->where('age_range', '>=', 18);
})
->get();