亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何解決“在數組上調用成員函數get()”:Laravel 5.4

如何解決“在數組上調用成員函數get()”:Laravel 5.4

PHP
Cats萌萌 2021-04-07 17:15:39
使用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);}
查看完整描述

1 回答

?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

$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"));


查看完整回答
反對 回復 2021-04-23
  • 1 回答
  • 0 關注
  • 164 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號