app/Http/Controllers/EnterpriseAreaController.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::where('enterprise_id', '=', Auth::guard('enterprises')->user()->id)->with(['Enterprise', 'User'])->orderBy('thanksDateTime', 'desc')->get();
        $filename = 'agradecimentos-empresa.csv';
        $handle = fopen($filename, 'w+');
        fputcsv($handle, array('Cliente', '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'], $thanksDateTime->format('d/m/Y H:i'), $enterpriseThank['content'], $enterpriseThank['replica'], $enterpriseThank['rejoinder']));
        }
        fclose($handle);
        $headers = array(
            'Content-Type' => 'text/csv',
        );
        return Response::download($filename, 'agradecimentos-empresa.csv', $headers);
    }
public function exportEnterpriseThanksRegister ( ) { $ enterpriseThanks = EnterpriseThanks :: where ( 'enterprise_id' , '=' , Auth :: guard ( 'enterprises' ) -> user ( ) -> id ) -> with ( [ 'Enterprise' , 'User' ] ) -> orderBy ( 'thanksDateTime' , 'desc' ) -> get ( ) ; $ filename = 'agradecimentos-empresa.csv' ; $ handle = fopen ( $ filename , 'w+' ) ; fputcsv ( $ handle , array ( 'Cliente' , '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' ] , $ thanksDateTime -> format ( 'd/m/Y H:i' ) , $ enterpriseThank [ 'content' ] , $ enterpriseThank [ 'replica' ] , $ enterpriseThank [ 'rejoinder' ] ) ) ; } fclose ( $ handle ) ; $ headers = array ( 'Content-Type' => 'text/csv' , ) ; return Response :: download ( $ filename , 'agradecimentos-empresa.csv' , $ headers ) ; }
Export enterprise thanks register to a CSV file.
Export enterprise thanks register to a CSV file .