0

my response to request in my laravel aplication is:

Array
(
[0] => Array
    (
        [order_product_id] => 39           
        [ean] => 1255AA
        [quantity] => 1       
    )

[1] => Array
    (   
        [order_product_id] => 40  
        [ean] => 1326489131511
        [quantity] => 1

    )

   )

How to parsing this data in my aplication? I tried to:

 foreach ($request->all() as $data)
 {
 print_r($data['ean']);
 die(); 
 } 

I get this error: Undefined index: ean

Edit: When I use var_export($request->all()) I get:

 array (
  'Array
(
____' => 
  array (
    0 => '> Array
        (
            [order_product_id] => 39
            [ean] => 1255AA
            [quantity] => 1
        )

    [1] => Array
        (
            [order_product_id] => 40
            [ean] => 1326489131511
            [quantity] => 1
        )    
)',
  ),
)

Thank you very much.

Milan
  • 11
  • 2

1 Answers1

0

It seems like $request->all() returns data as something like that:

$array = [
    'Array ( ____' => [
        [
            'order_product_id' => 39,
            'order_id' => 34,
            'product_id' => 48,
            'name' => 'iPod Classic',
            'model' => 'product 20',
            'ean' => '1255AA',
            'quantity' => '1',
            'price' => 10.0000,
            'total' => 10.0000,
            'tax' => 0.0000,
            'reward' => 0    
        ],
   ]    
];

So, instaed of:

foreach ($request->all() as $data)

use:

foreach (array_shift($request->all()) as $data)
VirCom
  • 3,414
  • 1
  • 10
  • 10
  • Thank you, but I get error: ErrorException: Only variables should be passed by reference in file .... on array_shift($request->all()) . – Milan May 05 '20 at 06:53
  • If you have result of command `var_export($request->all())`, there is something wrong. It looks line: ['Array ( ____'] => 0 => string Where string is: `'> Array ( [order_product_id] => 39 [ean] => 1255AA [quantity] => 1 ) [1] => Array ( [order_product_id] => 40 [ean] => 1326489131511 [quantity] => 1 ) )'` Could you paste result of var_export($_POST) yet ? – VirCom May 05 '20 at 07:20