Table of contents
In this tutorial, we will tackle Laravel Like Query where clause using the like operator.
Â
The Laravel Like Query is very useful when you are searching for a word or part of a word or paragraph in the column value.
Â
For example, you are searching for users having john
on their name.
Â
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$users = User::where('name', 'like', '%john%')->get();
dd($users);
}
}
Â
%john%
- searches exact value, the part between, part at the beginning, and part at the end.%john
- exact value, part at the endjohn%
- exact value, part at the beginning
Â
I hope it helps you understand more about Laravel like()
operator in where clause.
That's pretty much it.
Read next