Laravel LIke operator

The use of like operator is in the search form. When we search for a keyword, a post, a product or an object and we do not know its exact name, then what we do is we type a keyword in it and whatever is found with that word is brought inside the database and displayed. This is called like operator.

function chat_user_search(Request $req){

$data = DB::table('users')->where('name', 'like', '%'.$req->search.'%')->get();
foreach ($data as $key => $value) {

}

I have created a Laravel function above and explained the like operator. You can create a search bar using this function and connect it to this function through the backend. Now it depends on you whether you use this like function through ajax or without ajax.

 

 

Leave a Reply