0

My array ($response_array) is like this :

Array
(
    [Auth] => Array
        (
            [UserID] => test
            [UserIP] => 123
            [XmlVersion] => Testing Version
        )

    [SearchAvailRequest] => Array
        (
            [CountryCd] => ID
            [CityCd] => JOG
            [CheckIn] => 2016-01-08
            [CheckOut] => 2016-01-09
        )

    [SearchAvailResponse] => Array
        (
            [Hotel] => Array
                (
                    [0] => Array
                        (
                            [HotelNo] => 1
                            [HotelCode] => 321
                            [HotelName] => Test 1 Hotel
                            [RmGrade] => Deluxe
                            [RmGradeCode] => DLX
                        )

                    [1] => Array
                        (
                            [HotelNo] => 2
                            [HotelCode] => 212
                            [HotelName] => Test 2 & 1 Hotel
                            [RmGrade] => Deluxe
                            [RmGradeCode] => DLX
                        )

                )

        )

)

I want to send the hotel data to view

So the view display data like this :

Hotel Name
Check In
Check Out
City

I try like this :

Controller :

  ...
   return view('frontend.hotel.main_list_hotel',[
  'hotel' => $response_array['SearchAvailResponse']['Hotel']
]);
    ...

View :

 @foreach($hotel as $key=>$value)
{{ $key }}
{{ $value['HotelNo'] }}                     
@endforeach

I get hotel no & hotel name

How to get check in, check out, city and country?

Any suggestions on how I can solve this problem?

Thank you very much

3 Answers 3

2

You can pass the SearchAvailRequest array, in the same manner that you did the SearchAvailResponse array:

 ...
   return view('frontend.hotel.main_list_hotel',[
  'hotel' => $response_array['SearchAvailResponse']['Hotel'], 
  'city_info' => $response_array['SearchAvailRequest']
]);
Sign up to request clarification or add additional context in comments.

Comments

2

You can do something like this

return view('frontend.hotel.main_list_hotel', [
    'availability' => [
        'checkIn' => $response_array['SearchAvailRequest']['CheckIn'],
        'checkOut' => $response_array['SearchAvailRequest']['CheckOut'],
        'city' => $response_array['SearchAvailRequest']['CityCd'],
        'country' => $response_array['SearchAvailRequest']['CountryCd'],
        'hotels' => $response_array['SearchAvailResponse']['Hotel'],
    ]
]);

1 Comment

Or simpler: 'request' => $response_array['SearchAvailRequest'] and access the request items in the view when needed $request['CheckIn']
1

Why not try the with() Laravel method ?

return view('frontend.hotel.main_list_hotel')->with(compact(response_array['SearchAvailResponse']['Hotel']));

All datas are sending to view and you can use :

{{ $response_array['SearchAvailResponse']['Hotel'] }}

In your blade template.

1 Comment

The with method is the same as the second parameter of view()

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.