我阻塞了从laravel上的表导出一个excel文件,这是我的控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use Excel;
class ExportExcelController extends Controller
{
function Export()
{
$customer_data = DB::table('qualys')->get();
return view('export_excel')->with('customer_data', $customer_data);
}
function excel()
{
$customer_data = DB::table('qualys')->get();
$customer_array[] = array('ip','qid');
// dd($customer_data);
foreach($customer_data as $customer)
{
// dd($customer);
$customer_array[] = array(
'ip' => $customer->qid,
'qid' => $customer->ip
);
}
Excel::download('customer data', function($excel) use ($customer_array) {
$excel->setTitle('customer Data');
$excel->sheet('Customer Data', function($sheet) use ($customer_array)
{
$sheet->fromArray($customer_array, null, 'A1', false, false);
});
})->download('xls', 'test');
}
}我在第29行被阻塞,我无法取回文件,下面是错误:
Argument 2 passed to Maatwebsite\Excel\Excel::download() must be of the type string, object given, called in /var/www/html/qualys/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 223我已经测试了几个“代码”,但都不能工作:(你能帮我吗?诚心诚意。
发布于 2018-12-20 16:37:22
没关系,我知道如何使用最新版本的->第一个命令来输入:
php artisan make:export UsersExport --model=User然后创建要导出的数据库的模型
php artisan make:model User然后我的控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use Excel;
use App\Exports\QualysExport;
use App\Http\Controllers\Controller;
class ExportExcelController extends Controller
{
function Export()
{
$customer_data = DB::table('user')->get();
return view('export_excel')->with('customer_data', $customer_data);
}
public function excel()
{
return Excel::download(new UserExport, 'Users.xlsx');
}
}然后下载文件的路径:
Route::get('/excel_export/excel', 'ExportExcelController@excel')->name('export_excel.excel');下载来了!由衷地
发布于 2018-12-20 00:21:56
你可以试试这段代码,
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use Excel;
class ExportExcelController extends Controller
{
function Export()
{
$customer_data = DB::table('qualys')->get();
return view('export_excel')->with('customer_data', $customer_data);
}
function excel()
{
$customer_data = DB::table('qualys')->get();
$customer_array[] = array('ip','qid');
// dd($customer_data);
foreach($customer_data as $customer)
{
// dd($customer);
$customer_array[] = array(
'ip' => $customer->qid,
'qid' => $customer->ip
);
}
// change download to create
Excel::create('filename', function($excel) use ($customer_array) {
$excel->setTitle('customer Data');
$excel->sheet('Customer Data', function($sheet) use ($customer_array)
{
$sheet->fromArray($customer_array, null, 'A1', false, false);
});
})->download('xls');
// donwload method only accept one parament and that is file extension
}
}https://stackoverflow.com/questions/53854014
复制相似问题