Level 122
$items = Item::query()
->with(['image'])
->where('title', 'LIKE', "{$term}%")
->paginate(12);
returns all records that have title starting with $term
2 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi All! I need to query my db records by a starting first letter or number only, nothing more. In my SearchController, I have the following, but it returns all records containing the given term in the title. Is there a way to do this? Thanks.
// SearchController.php
public function browse($term)
{
$items = Item::query()
->with(['image'])
->where('title', 'LIKE', "%{$term}%")
->paginate(12);
return view('items.browse', compact(['items', 'term']));
}
$items = Item::query()
->with(['image'])
->where('title', 'LIKE', "{$term}%")
->paginate(12);
returns all records that have title starting with $term
Please or to participate in this conversation.