0

I'm trying to pass an object into the Laravel Excel sheet method but I'm not sure how. I get an undefined variable error - which I realize is because I'm inside a function that doesn't have scope to reach the object.

Ultimately I'm loading up regtypes from one table - attendees from another and creating a sheet for each regtype that contains all attendees of that type.

My code:

public function export() 
{
    $date = date('Y_m_d');
    \Excel::create('CMO_Connect_Attendees_Export_'.$date, function($excel) {
    $regtypes = Regtype::all();
    foreach ($regtypes as $regtype) {
        if( $regtype->attendees(3)->count() ) {

        $excel->sheet('Attendees', function($sheet) {
            $date = date('Y_m_d');
            $attendees = new Attendee;

            $atts = Attendee::where('block_id', '=', \Input::get('block_id'))
                ->where('regtype_id', '=', $regtype->id)
                ->get();
                $sheet->setStyle(array(
                    'font' => array(
                        'name'      =>  'Arial',
                        'size'      =>  12,
                        'bold'      =>  false
                    )
                ));
            $sheet->loadView('attendees.export', array('atts' => $atts))->with('curdate',$date)->with('regtype_name',$regtype->name);

        });
        } //endif
    } //endforeach

    $excel->export('xls');
    });
}
Dylan Glockler
  • 1,115
  • 1
  • 20
  • 40

1 Answers1

0

As I was writing this up I figured it out, pretty simple I should have known as it's simply a method of a Laravel Facade, so you pass the object as an array like so:

            $excel->sheet('Attendees',  array('regtype' => $regtype), function($sheet) {
Dylan Glockler
  • 1,115
  • 1
  • 20
  • 40