首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何修复“调用数组上的成员函数get()”:Laravel 5.4

如何修复“调用数组上的成员函数get()”:Laravel 5.4
EN

Stack Overflow用户
提问于 2019-04-15 01:57:50
回答 1查看 7K关注 0票数 0

我在使用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);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-15 02:05:18

$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"));
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55678345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档