I wish the URL would get created even if the user types half of the keyword.
Have you tried Str::contains()
@if(Illuminate\Support\Str::contains($search, $keyword)) {
// link
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I wish to capture a given keyword from a text field, whatever is in the field, it should then be stored in a variable that will be passed to another one, the last of which will be searching the key for this associated keyword, and it should respond with an associative array.
Below im making that Http get request and im binding the $keyword variable into the URL
public function keywordSearch($keyword)
{
$keywordVideos = Http::get('http://thvid-api.herokuapp.com/videos/keyword/'. $keyword)->json();
$keywordVideo = $keywordVideos[0];
return view ('videos.keyword', compact('keywordVideo'));
}
Once it finds something valid, this should be able to be passed to a URL. The URL created will be validated against an if statement like this:
@if ($search === $keyword)
<a href="videos/keyword/{{ $keyword }}/{{ $key }}">
For example, user typed: "proskater",
@if ($search === 'proskater')
<a href="videos/keyword/proskater/{{ $key }}">
Example response:
{
"_id": "605a43ea667cd39060f43687",
"Title": "Buck - \"Proskater\" (THUG Pro 2019)",
"Game": "THUG Pro",
"ID": "5W-jnqHqVNM",
"Thumbnail": "https://i.ytimg.com/vi_webp/5W-jnqHqVNM/maxresdefault.webp",
"newduration": "00:05:36"
},
How can I build this? Do you use the Spatie Query Builder library? or Laravel Macros? Ultimately I wish the URL would get created even if the user types half of the keyword. Thanks!
Please or to participate in this conversation.