0

Trying to send an confirmation Email using Laravel 4.2. But hitting an error in the view

Undefined variable: booking_data

I am trying to pass it the following data array :

["from"]=>
  string(7) "Gatwick"
  ["to"]=>
  string(8) "Aberdeen"
  ["leaving"]=>
  string(21) "Friday, 15 July, 2016"
  ["returning"]=>
  string(24) "Wednesday, 20 July, 2016"
  ["price"]=>
  string(2) "53"
  ["hotel"]=>
  string(9) "Four Star"
  ["date_start"]=>
  string(10) "2016-07-15"
  ["date_end"]=>
  string(10) "2016-07-20"
  ["insurance"]=>
  string(0) ""
  ["num_travellers"]=>
  string(1) "1"
  ["car_hire"]=>
  string(0) ""
  ["baggage"]=>
  string(0) ""
  ["car_hire_days"]=>
  string(0) ""
  ["flight_cost"]=>
  string(2) "53"
  ["new_cost"]=>
  string(6) "383.00"
  ["hotel_transport"]=>
  string(0) ""
  ["passengers"]=>
  array(1) {
    [0]=>
    array(5) {
      ["firstname"]=>
      string(6) "Stuart"
      ["surname"]=>
      string(8) "Blackett"
      ["address2"]=>
      string(17) "Line 1"
      ["town"]=>
      string(12) "Town"
      ["passportnumber"]=>
      string(2) "TS"
    }
  }
  ["user_email"]=>
  string(27) "[email protected]"
  ["user_phone"]=>
  string(2) "01"

My current Laravel Controller code is :

// Create View Confirming Payment....
$booking_data = Session::all();

// Send Confirmation To User & Site Admin...
$user_email = Session::get('user_email');

Mail::send('emails.confirmation', $booking_data, function($message) use ($booking_data)
{
    $message->from('[email protected]', 'In The Air Deals');

    $message->to(Session::get('user_email'))
        ->cc('[email protected]')
        ->subject('Booking Confirmation from In The Air Deals');
});

In the view I am using blade and doing the following :

@foreach ($booking_data['passengers'] as $passenger)
   <tr>
   <td>Name:</td>
   <td>
   {{ $passenger->firstname }}
   {{ $passenger->surname }}
   </td>
   </tr>
   <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   </tr>
   <tr>
   <td>Address:</td>
   <td>
   {{ $passenger->address1 }}
   <br />
   {{ $passenger->address2 }}
   {{ $passenger->town }}
  </td>
 </tr
@endforeach

Is there something else I need to do, To get the booking data passed to the view?

Thanks

0

1 Answer 1

1

try this:

@foreach ($passengers as $passenger)
   <tr>
   <td>Name:</td>
   <td>
   {{ $passenger->firstname }}
   {{ $passenger->surname }}
   </td>
   </tr>
   <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   </tr>
   <tr>
   <td>Address:</td>
   <td>
   {{ $passenger->address1 }}
   <br />
   {{ $passenger->address2 }}
   {{ $passenger->town }}
  </td>
 </tr
@endforeach
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, I see each item in the array is made into an object. Thank you for that!

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.