从 Laravel 中的数组(来自 API)获取数据

Get data from array (from an API) in Laravel

这是我第一次使用外部 API。我已经修复它给了我正确的输出。在控制器中,我有以下代码:

public function index() {
    $api = new Wefact();

    $parameters = [
    ];

    $api_response = $api->sendRequest('product', 'list', $parameters);

    print_r($api_response);

}

这显示了页面上的数组。但是我不知道如何使用这个数组将它放到blade中的一个foreach中。 print_r 的输出如下:

Array
(
    [controller] => product
    [action] => list
    [status] => success
    [date] => 2022-05-05T04:20:03+02:00
    [totalresults] => 2
    [currentresults] => 2
    [offset] => 0
    [products] => Array
        (
            [0] => Array
                (
                    [Identifier] => 1
                    [ProductCode] => P0001
                    [ProductName] => SIM ONLY 5GB
                    [ProductKeyPhrase] => SIM ONLY 5GB
                    [ProductDescription] => 
                    [NumberSuffix] => 
                    [PriceExcl] => 25
                    [TaxCode] => V21
                    [TaxPercentage] => 21
                    [PricePeriod] => m
                    [Modified] => 2022-05-05 03:49:57
                )
 
            [1] => Array
                (
                    [Identifier] => 2
                    [ProductCode] => P0002
                    [ProductName] => SIM ONLY 10GB
                    [ProductKeyPhrase] => SIM ONLY 10GB
                    [ProductDescription] => 
                    [NumberSuffix] => 
                    [PriceExcl] => 35
                    [TaxCode] => V21
                    [TaxPercentage] => 21
                    [PricePeriod] => m
                    [Modified] => 2022-05-05 04:03:47
                )
 
        )
 
)

如您所见,有两种产品。我想将这些放在带有 foreach 的数据表中。 由于我是第一次,我真的不知道该怎么做。

谁能帮帮我?

如果你想访问 array 的产品,它会像这样

return view('your_view', [
  'products' => $api_response['products']
]);