app/Http/Controllers/ServiceAdminController.php
/**
     *
     * Export enterprise thanks register to a CSV file.
     * 
     * @return Response
     * 
     */
Export enterprise thanks register to a CSV file.

@return Response
Export enterprise thanks register to a CSV file . @return Response
public function exportEnterpriseThanksRegister()
    {
        $enterpriseThanks = EnterpriseThanks::with(['Enterprise', 'User'])->orderBy('thanksDateTime', 'desc')->get();
        $filename = 'agradecimentos-empresas.csv';
        $handle = fopen($filename, 'w+');
        fputcsv($handle, array('Usuário', 'Empresa', 'Data/Hora', 'Agradecimento', 'Réplica', 'Tréplica'));
        foreach($enterpriseThanks as $enterpriseThank) {
        	$thanksDateTime = \DateTime::createFromFormat('Y-m-d H:i:s', $enterpriseThank['thanksDateTime']);
            fputcsv($handle, array($enterpriseThank['user']['name'], $enterpriseThank['enterprise']['name'], $thanksDateTime->format('d/m/Y H:i'), strip_tags($enterpriseThank['content']), strip_tags($enterpriseThank['replica']), strip_tags($enterpriseThank['rejoinder'])));
        }
        fclose($handle);
        $headers = array(
            'Content-Type' => 'text/csv',
        );
        return Response::download($filename, 'agradecimentos-empresas.csv', $headers);
    }
public function exportEnterpriseThanksRegister ( ) { $ enterpriseThanks = EnterpriseThanks :: with ( [ 'Enterprise' , 'User' ] ) -> orderBy ( 'thanksDateTime' , 'desc' ) -> get ( ) ; $ filename = 'agradecimentos-empresas.csv' ; $ handle = fopen ( $ filename , 'w+' ) ; fputcsv ( $ handle , array ( 'Usuário', Empresa', Data/Hora', Agradecimento', Réplica',  ' réplica')); foreach ( $ enterpriseThanks as $ enterpriseThank ) { $ thanksDateTime = \ DateTime :: createFromFormat ( 'Y-m-d H:i:s' , $ enterpriseThank [ 'thanksDateTime' ] ) ; fputcsv ( $ handle , array ( $ enterpriseThank [ 'user' ] [ 'name' ] , $ enterpriseThank [ 'enterprise' ] [ 'name' ] , $ thanksDateTime -> format ( 'd/m/Y H:i' ) , strip_tags ( $ enterpriseThank [ 'content' ] ) , strip_tags ( $ enterpriseThank [ 'replica' ] ) , strip_tags ( $ enterpriseThank [ 'rejoinder' ] ) ) ) ; } fclose ( $ handle ) ; $ headers = array ( 'Content-Type' => 'text/csv' , ) ; return Response :: download ( $ filename , 'agradecimentos-empresas.csv' , $ headers ) ; }
Export enterprise thanks register to a CSV file.
Export enterprise thanks register to a CSV file .