laravel查询生成器上聚合函数的动态别名



我想要一个count((函数的动态别名。

我使用mysql5.7作为数据库。

这是代码。

$date = Carbon::parse('2021-03-11')
DB::table('payments')
->select(DB::raw('IFNULL(sum(amount),0) as :date'), $date)
->get();

我有这个错误

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?, `2021-03-11` from `payments`' at line 1 (SQL: select IFNULL(sum(amount),0) as :date, `2021-03-11` from `payments`)

我期待这个结果

|2021-03-11|
|<amount_here>|

试试这样的东西:

$date = Carbon::parse('2021-03-11')
DB::table('payments')
->select(DB::raw('IFNULL(sum(amount),0) as "?"', [$date])
->get();