2

I'm connecting my laravel application with firebase and I successfully get the following response:

array:1 [▼
    "-KvJja_r0beLtdoRc29f" => array:5 [▼
        "accepted" => "true"
        "date" => "1/10/2017"
        "hour" => "0:43"
        "numberOfPeople" => ""
        "tableInfo" => ""
    ]
]

I want to know how to get the value "-KvJja_r0beLtdoRc29f" from this response. I tried looping with foreach, but I get the inner data not the key.

I tried

@foreach($reservations as $reservation)

then printing the results but I get the

"accepted" => "true"
"date" => "1/10/2017"
"hour" => "0:43"
"numberOfPeople" => ""
"tableInfo" => ""

How can I do this?

FirstOne
  • 6,033
  • 7
  • 26
  • 45
Nadin
  • 73
  • 1
  • 8

1 Answers1

5

Use can use $key inside foreach() to get key value. Do like below:-

@foreach($reservations as $key=> $reservation)
  echo $key; // output -KvJja_r0beLtdoRc29f

Sample Output:- https://eval.in/937628

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98