There is a response in json format (the request was sent via Guzzle Laravel, I used a ready-made API), I deserialized it via json_decode.
public function raspget(RaspRequest $request) { $client = new Client([ 'base_uri' => 'http://localhost:8080', ]); $attributes = $request->only(['departure_station', 'arrival_station', 'date']); $response = $client->request('GET', 'https://api.rasp.yandex.net/v3.0/search/', [ 'query' => [ 'apikey' => 'I_WONT_TELL_YOU', 'from' => $attributes['departure_station'], 'to' => $attributes['arrival_station'], 'date' => $attributes['date'], 'lang' => 'ru_RU', 'transport_types' => 'suburban', ] ]); $times = json_decode($response->getBody(), true); return view('rasps.raspgot')->withTimes($times); }
Since the answer keeps the schedule for the current day, I need to display it in the blade in the table through the foreach loop. I get an error: Undefined Index. How do I get data from the response and output to the blade? The structure of the answer here: https://tech.yandex.ru/rasp/doc/reference/schedule-point-point-docpage/
Undefined Index
means that you are trying to get an element of an array that does not exist. Perhaps in your template, an attempt to get an element that is not in$times
or an error in writing the key - Dmitry Kozlov