Laravel where Like Query Example

In this tutorial you will learn about the Laravel where Like Query Example and its application with practical example.

In this Laravel where like query example tutorial I’ll show you how to use laravel whereLike() method with query builder in laravel. You also learn how to use whereLike() eloquent method in search query. I’ll also show you how to use laravel where like for multiple like condition. In this tutorial I’ll demonstrate you different use case of the laravel whereLike method with examples.

Laravel where Like Query use with Model

Laravel whereLike() method is simple implementation of MySQL Like keyword. In laravel you can use % wildcard character with whereLike condition in similar as you do in mysql like.

Example:-

The above given Where like query you will get the following SQL query:

Using macros with Like

In laravel you can define a macro using the macro static method in class you want to define the macro for. We need to define a macro for the Eloquent class, so we can extend it as following:

Laravel whereLike with multiple columns using macros

In laravel when you want to search with multiple columns then you can exten this macro to support multiple columns as following:

In this tutorial we have learn about the Laravel where Like Query Example and its application with practical example. I hope you will like this tutorial.