When trying to screw the currency informer on laravel 5.2, I ran into a problem. When displaying, I get the error Undefined index: USD (View: .......
That's what I have in the controller
public function getNBUCur() { // Список валют по умолчанию define('_DEFOUT','USD.EUR.RUB',true); // Проверяем наличие параметра if (isset($_GET['out'])){ if (ctype_alnum(str_replace('.','',$_GET['out']))){ define('_GETOUT',$_GET['out'],true); } } define('_VALOUT',(defined('_GETOUT')?_GETOUT:_DEFOUT),true); // Получаем курсы на текущую дату $NBUDoc = simplexml_load_file('http://bank-ua.com/export/currrate.xml'); $NBUDat = []; // Пихаем всё в ассоциативный массив foreach ($NBUDoc->children() as $NBUItem){ $charCode = strval($NBUItem->char3); $result = [ 'date' => strval($NBUItem->date), 'char3' => strval($NBUItem->char3), 'name' => strval($NBUItem->name), 'size' => strval($NBUItem->size), 'rate' => strval($NBUItem->rate), 'change' => strval($NBUItem->change) ]; $NBUDat[$charCode] = $result; $this->data['NBUDat'] = $NBUDat[$charCode]; } // Выводим таблицу $_TOOUT = explode('.', _VALOUT); $this->data['_TOOUT'] = $_TOOUT; return view('components.informer', $this->data); } In the template:
<table> <thead> <tr> <b>НБУ</b> <td>Курс к UAH</td> <td>Курс НБУ</td> <td>Динамика</td> <td>Дата</td> </tr> </thead> <tbody> @foreach ($_TOOUT as $_KEY => $_VAL) <tr> <td class='ccy'>{{ $NBUDat[$_VAL]['char3'] }}</td> <td class='buy'>{{ $NBUDat[$_VAL]['rate'] }}</td> <td class='change'>{{ $NBUDat[$_VAL]['change'] }}</td> <td class='date'>{{ $NBUDat[$_VAL]['date'] }}</td> </tr> @endforeach </tbody> </table> If anyone can, please tell me how to fix it.
In a separate file, the code works as expected. It also works in laravel, if all the code is put into the controller, and in the template it is easy to call this method. I decided to try to divide this code so that the table was displayed in the template, and not in the controller ... and then got stuck.