app/Http/Controllers/ReportEnterpriseController.php
/**
	 * Export religion data to a CSV file.
	 *
	 * @return Response
	 */
Export religion data to a CSV file.
@return Response
Export religion data to a CSV file . @return Response
public function exportReligionData($start, $end)
	{
		$thanksByReligions = User::select('religion', \DB::raw("count(users.religion) as thanks"))->whereBetween('thanksDateTime', array(new Carbon($start), new Carbon($end)))->join('enterprise_thanks', 'enterprise_thanks.user_id', '=', 'users.id')->groupBy('users.religion')->get();
        $filename = 'agradecimentos-por-religiao.csv';
        $handle = fopen($filename, 'w+');
        fputcsv($handle, array('Religião', 'Número de agradecimentos'));
        foreach($thanksByReligions as $thanksByReligion) {
        	if ($thanksByReligion['religion'] == '' || $thanksByReligion['religion'] == null) {
        		$thanksByReligion['religion'] = "Não informado";
        	}
        	fputcsv($handle, array($thanksByReligion['religion'], $thanksByReligion['thanks']));
        }
        fclose($handle);
        $headers = array(
            'Content-Type' => 'text/csv',
        );
        return Response::download($filename, 'agradecimentos-por-religiao.csv', $headers);
	}
public function exportReligionData ( $ start , $ end ) { $ thanksByReligions = User :: select ( 'religion' , \ DB :: raw ( " count(users.religion) as thanks " ) ) -> whereBetween ( 'thanksDateTime' , array ( new Carbon ( $ start ) , new Carbon ( $ end ) ) ) -> join ( 'enterprise_thanks' , 'enterprise_thanks.user_id' , '=' , 'users.id' ) -> groupBy ( 'users.religion' ) -> get ( ) ; $ filename = 'agradecimentos-por-religiao.csv' ; $ handle = fopen ( $ filename , 'w+' ) ; fputcsv ( $ handle , array ( 'Religião', Número de agradecimentos')) ; foreach ( $ thanksByReligions as $ thanksByReligion ) { if ( $ thanksByReligion [ 'religion' ] == '' || $ thanksByReligion [ 'religion' ] == null ) { $ thanksByReligion [ 'religion' ] = " Não informado" ; } fputcsv ( $ handle , array ( $ thanksByReligion [ 'religion' ] , $ thanksByReligion [ 'thanks' ] ) ) ; } fclose ( $ handle ) ; $ headers = array ( 'Content-Type' => 'text/csv' , ) ; return Response :: download ( $ filename , 'agradecimentos-por-religiao.csv' , $ headers ) ; }
Export religion data to a CSV file.
Export religion data to a CSV file .