jeudi 7 avril 2016

laravel csv , how to get csv file with front zeros

when I generate my csv file , some of the special charactors and front zero of cell values are not getting . pls advice how to fix this

    public function csv()
    {
        // $table = Festivals::all();
        $headers = [
            'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0'
            , 'Content-type' => 'text/csv'
            , 'Content-Disposition' => 'attachment; filename=sss.csv'
            , 'Expires' => '0'
            , 'Pragma' => 'public'
        ];

              $list = Festivals::select('ref_no','artist_name','postal_address','payment','payment_fee','bank_details','bank_name','bank_address','account_name','account_number','sort_code','reg_vat','vat_reg_number'
,'foreign_artise','name_desg','email','mobile','name_address','vehicle_size','backline','additional_backline','name','date')->get()->toArray();


        # add headers for each column in the CSV download
        array_unshift($list, array_keys($list[0]));

        $callback = function () use ($list) {
            $FH = fopen('php://output', 'w');
            foreach ($list as $row) {
                fputcsv($FH, $row);
            }
            fclose($FH);
        };

        return Response::stream($callback, 200, $headers);
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire