0

Hi i'm trying to use the ID of the route to create a list of players for that tournament. However i can't seem te get the ID to be availble inside my excel creator.

enter image description here

Route::get('toernooien/{id}/spelers/excelexport', function($id){
        Excel::create('Export spelers toernooi '. $id, function($excel) {
            $excel->sheet('Sheetname', function($sheet) {
                $ingeschrevenspelers = \App\UserToernooi::with('users')->where('toernooiid', '=', $id)->get()->all();
                foreach($ingeschrevenspelers as $ingeschrevenspeler){
                    $sheet->row($ingeschrevenspeler->users->id, array(
                        'Voornaam:' . $ingeschrevenspeler->users->voornaam,
                        'Tussenvoegsel:' . $ingeschrevenspeler->users->tussenvoegsel,
                        'Achternaam:' . $ingeschrevenspeler->users->achternaam,
                        'Woonplaats:' . $ingeschrevenspeler->users->woonplaats,
                        'Telefoonnummer:' . $ingeschrevenspeler->users->telefoonnummer,
                        'e-mail:' . $ingeschrevenspeler->users->email,
                    ));
                }
            });

        })->download('xls');
    });

I would like to use the highlighted ID in the get route function inside my $ingeschrevenspelers var to get the list of users subscribed to that tournament. I tried adding the $id var next to $excel and $sheet but nothing seems to be working.

I'm using http://www.maatwebsite.nl/laravel-excel/docs/export as excel exporter.

Thanks in advance

Jordy

2 Answers 2

2

In this line:

Excel::create('Export spelers toernooi '. $id, function($excel) {

you need to change it to:

Excel::create('Export spelers toernooi '. $id, function($excel) use ($id) {

As you need to pass the variables that will be used inside Anonymous functions using 'use' keyword

0
1

it won't be available because you are using it inside an anonymous function.

change the your code from

Excel::create('Export spelers toernooi '. $id, function($excel) {

to

Excel::create('Export spelers toernooi '. $id, function($excel) use ($id) {

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.