[英]How to fix “Call to a member function get() on array” : Laravel 5.4
我在使用maatwebsite / laravel-excel从数据库下载我生成数据的文件时遇到问题。 错误:在数组上调用成员函数get()。
之前,当我仅使用一个字段从数据库中选择数据时,该文件可以生成(.csv)。 但是当我尝试使用别名“as”查询时,无法获取数据。
public function getdoc($type)
{
-- with this query : success --
//$temp = AlarmV2::select('msisdn')->get();
$today = "20181008";
-- with this query : error --
$temp = DB::select(DB::raw("select regionalid,
nvl(sum(case when lastactiontype='0' then totalcharge end),0) as creditlimit_usage,
count(case when lastactiontype='0' then msisdn end) as creditlimit_rec,
from alarms_v2
where alarmdate = '$today'
-- fatal error exception :Call to a member function get() on array --
group by regionalid order by regionalid"))->get();
return Excel::create('datadoc', function ($excel) use ($temp) {
$excel->sheet('mySheet', function ($sheet) use ($temp) {
$sheet->fromArray($temp);
});
})->download($type);
}
$temp = DB::select(DB::raw("select regionalid,
nvl(sum(case when lastactiontype='0' then totalcharge end),0) as creditlimit_usage,
count(case when lastactiontype='0' then msisdn end) as creditlimit_rec,
from alarms_v2
where alarmdate = '$today'
-- fatal error exception :Call to a member function get() on array --
group by regionalid order by regionalid"))->get();
在这里,您不需要调用get()
方法。 因为select()方法已经执行了查询并返回结果数组。 所以,就像下面这样做:
$temp = DB::select(DB::raw("select regionalid,
nvl(sum(case when lastactiontype='0' then totalcharge end),0) as creditlimit_usage,
count(case when lastactiontype='0' then msisdn end) as creditlimit_rec,
from alarms_v2
where alarmdate = '$today'
group by regionalid order by regionalid"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.