The database query builder in Laravel provides a simple, intuitive interface for generating and performing database queries. It works with every one of Laravel's supported database systems and may be used to conduct most operations on the database in your application.

This article will teach you how to utilize select like queries in a Laravel application.

Laravel eloquent, in theory, provides a query builder that helps us to handle that kind of situation in MySQL. This is quite simple to use, or you could say a no-brainer.

"Query Builder" deserves a standing ovation. It can assist you in writing a Like query in Laravel, and keep in mind that it is utilized with the Where condition.

Like the query, Laravel Eloquent is mostly used to search the particular value of the table's selected column.

As a result, you can use one of the methods listed below.

1. WHERE Condition with Like Query in Laravel with Query Builder

Let me give you an example: imagine you have a couple of nation values in your table for the countries (USA, UK, France, and China). And you wish to exclude the worth of France.

<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
class CountryController extends Controller
{
    public function index()
    {
        $term = 'France';
        $filterData = DB::table('countries')->where('name','LIKE','%'.$term.'%')
                      ->get();
                      
        print_r($filterData);
    }
}

2. Like Query with Laravel Model

We can also utilize the laravel model to perform the Like Query with Where clause; below is an example that you should look at.

<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Country;
class CountryController extends Controller
{
    public function index()
    {
        $term = 'France';
        $filterData = Country::table('countries')->where('name','LIKE','%'.$term.'%')
                      ->get();
        print_r($filterData);
    }
}

I hope you will like the content and it will help you to learn Laravel Eloquent WHERE Like Query Example Tutorial
If you like this content, do share.


Recommended Posts

View All

Laravel 9 File Manager Tutorial Example


Learn how to implement a robust file manager in Laravel 9 with our step-by-step tutorial. This example will help you manage and organize files efficie...

Laravel Google Chart Example Tutorial


laravel google chart example, dynamic charts in laravel, laravel google pie chart, laravel google line chart example, google chart in laravel, laravel...

How to perform CURL requests using ixudra/curl in Laravel


Laravel&#39;s ixudra package offers an effective method for making HTTP requests using curl.

Laravel Where Clause with MySQL Function Example


laravel eloquent where year,laravel eloquent mysql functions,laravel eloquent where clause mysql,mysql function mysql laravel

Laravel 9 Socialite Login with LinkedIn Tutorial Example


How to use the Laravel socialite, Livewire, and Jetstream libraries to create a LinkedIn login system from scratch in Laravel