首页 > 解决方案 > 调用字符串上的成员函数 where()

问题描述

我打算用laravel框架​​开发网络。这是我的代码:

$valws = DB::table('layananpublik')->sum('value')->where('tahun',$tahun)->where('bulan',$stringbln)->where('kategori',$PilihKat);

我得到一个错误:

JobHarianController.php 第 195 行中的 FatalErrorException:调用字符串上的成员函数 where()

标签: phplaravel-5error-handlingwhere-clause

解决方案


尝试这个,

$valws = DB::table('layananpublik')
       ->where('tahun', '=',$tahun)
       ->where('bulan', '=',$stringbln)
       ->where('kategori', '=',$PilihKat)
       ->sum('value');

或者

$valws = DB::table('layananpublik')
       ->select(DB::raw("SUM(value) as value")) 
       ->where('tahun', '=',$tahun)
       ->where('bulan', '=',$stringbln)
       ->where('kategori', '=',$PilihKat)
       ->get();

推荐阅读