1

It is my first time working with an external API. I have already fixed that it gives me the right output. In a controller I have the following code:

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

    $parameters = [
    ];

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

    print_r($api_response);

}

This shows me the array on the page. But I do not know how to use this array to get it into a foreach in the blade. The output of the print_r is as follow:

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
                )
 
        )
 
)

As you can see there are two products. I want to have these in a datatable with an foreach. Since it is my first time, I really do not know how to do this.

Anyone that can help me out?

1
  • do you use datatable for showing data from API !? datatables.net ?? Commented May 5, 2022 at 4:01

1 Answer 1

1

If you want to access the array of products it would be like this

return view('your_view', [
  'products' => $api_response['products']
]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.