仅导出单个记录 Headers 不导出数据 (laravel 5.3)

Export a single record only Headers downing not the data (laravel 5.3)

我正在尝试从数据库中导出单条记录。我尝试编写不同的方法但失败了。现在我在这里试试这个,它只是下载 headers 而没有数据。

public function getExport($id) {
    $student = Students::find($id);
    $filename = "students.csv";
    $handle = fopen($filename, 'w+');
    fputcsv($handle, array('name', 'class', 'section'));

    foreach($student as $row) {
        fputcsv($handle, array($row['name'], $row['class'], $row['section']));
    }

    fclose($handle);

    $headers = array(
        'Content-Type' => 'text/csv',
    );

    return Response::download($filename, 'Students.csv', $headers);
}

这里只给出 table 头部而不是下面的数据。我怎样才能得到所有?

更新 v3 根据评论。

public function getExport($id)
    {
        $student = Students::find($id);
        $filename = $student->name . ".csv";
        $handle = fopen($filename, 'w+');
        fputcsv($handle, array('name', 'class', 'section'));
        fputcsv($handle, array($student->name, $student->class, $student->section));

        fclose($handle);

        $headers = array(
            'Content-Type' => 'text/csv',
        );

        return \Response::download($filename, $filename, $headers);
    }