Laravel Search Tutorial: Building a Simple Search Feature

Learn how to build a basic search feature in Laravel using query builder LIKE queries, combined with filters and pagination.

Almost every list of data — products, users, blog posts — eventually needs a search box. This tutorial covers building a simple, effective search feature using Laravel's query builder. Step 1: Build the Search Form <form method="GET" action="{{ route('products.index') }}"> <input type="text" name="search" value="{{ request('search') }}" placeholder="Search products..."> <button type="submit">Search</button> </form> Using GET (not POST ) keeps the search term visible in the URL — useful for sharing links and browser back/forward navigation. Step 2: Filter Results in the Controller public function index(Request $request) { $search = $request->input('search'); $products = Product::when($search, function ($query, $search) { $query->where('name', 'like', "%{$search}%"); }) ->paginate(10); return view('products.index', compact('products')); } when() on...

Home · Projects · Articles · Developer tools · Contact