25 lines
558 B
PHP
25 lines
558 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Common;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests;
|
|
use App\Http\Controllers\Controller;
|
|
use Excel;
|
|
use Exception;
|
|
|
|
class ExcelController extends Controller {
|
|
|
|
public function export($filename, $data) {
|
|
if(count($data)==0){
|
|
throw new Exception('No data');
|
|
}
|
|
Excel::create($filename, function($excel) use($data){
|
|
$excel->sheet('sheet', function($sheet) use($data) {
|
|
$sheet->fromArray($data);
|
|
});
|
|
})->export('xls');
|
|
}
|
|
|
|
}
|