Laravel 8 download csv method

public function downloadDistancesResults(){

        $fileName = 'distance_results.csv';
        $dc_results = DB::table('distance_calculation')->get()->all();
        //echo '<pre>';print_r($dc_results);die;
        $headers = array(
            "Content-type"        => "text/csv",
            "Content-Disposition" => "attachment; filename=$fileName",
            "Pragma"              => "no-cache",
            "Cache-Control"       => "must-revalidate, post-check=0, pre-check=0",
            "Expires"             => "0"
        );

        $columns = array('Name', 'Dealer Address', 'Venue Address', 'Distance KM', 'Distance Time');

        $callback = function() use($dc_results, $columns) {
            $file = fopen('php://output', 'w');
            fputcsv($file, $columns);

            foreach ($dc_results as $task) {
                $row['name']  = $task->name;
                $row['address']    = $task->address;
                $row['venue']    = $task->venue;
                $row['distance_km']  = $task->distance_km;
                $row['distance_time']  = $task->distance_time;

                fputcsv($file, array($row['name'], $row['address'], $row['venue'], $row['distance_km'], $row['distance_time']));
            }

            fclose($file);
        };

        return response()->stream($callback, 200, $headers);


    }