In this tutorial you will learn about the Laravel 8 Eloquent WHERE Like Query Example Tutorial and its application with practical example.
In this Laravel 8 Eloquent WHERE Like Query Example Tutorial I’ll show you how to use laravel like with where method with query builder in laravel. You also learn how to use like in where 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 8 Eloquent WHERE Like Query Example Tutorial
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.
Like Query with WHERE Condition in Laravel with Query Builder
In this example I have demonstrated you how to use “LIKE” in where method with query builder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?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); } } |
Like Query with Laravel Model
In this example I have demonstrated you how to use “LIKE” in where method with laravel model.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?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); } } |