Ad

Laravel 4 - Mail Send (Variable Undefined)

- 1 answer

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

Ad

Answer

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
Ad
source: stackoverflow.com
Ad