query->get("q"); if ($query) { // O(n) query at best, malicious users can just insert % and _ characters into the query if they wanna, but it's fine half the class left every single field vulnurable to sqli so I don't wanna bother doing this properly with a full text search $products = Product::query()->where('name', 'like', "%{$query}%")->orWhere('description', 'like', "?")->latest()->limit(100)->get(); } else { $products = Product::query()->latest()->limit(100)->get(); } return view("index", ["products" => $products, "query" => $query]); } }