public function form(){
return view(‘search’);
}
public function fetchData()
{
$client = new Client();
try {
$response = $client->request('GET', 'https://musicapi13.p.rapidapi.com/public/search/introspection', [
'headers' => [
'X-RapidAPI-Host' => 'host',
'X-RapidAPI-Key' => 'my key',
],
]);
$data = json_decode($response->getBody(), true);
// Pass the data to the view
return view('fetch-data', ['fetchedData' => $data]);
} catch (\Exception $e) {
// Handle exceptions, log errors, etc.
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function search(Request $request)
{
$client = new Client();
try {
$response = $client->request('POST', 'https://musicapi13.p.rapidapi.com/public/search', [
'body' => json_encode([
'track' => $request->input('search'),
'type' => 'track',
'sources' => ['spotify'],
]),
'headers' => [
'X-RapidAPI-Host' => 'host',
'X-RapidAPI-Key' => 'my key',
'Content-Type' => 'application/json',
],
]);
$data = json_decode($response->getBody(), true);
return view('search-results', ['searchResults' => $data]);
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
blade template code
@foreach ($fetchedData[‘sources’] as $source)
<li>{{ $source }}</li>
@endforeach
</ul>
my form
<form action="{{ route(‘search’) }}" method=“POST”>
@csrf
<input type=“search” name=“search”>
<button type=“submit”>submit</button>
</form>
when i enter name any song
error
{
“error”: “View [search-results] not found.”
}
any one help me solve issue
Junte-se à discussão - adicione o comentário abaixo: