我想从我的事件表中选择给定日期的所有行。为此,我使用了 whereRaw()
子句。这是我执行此操作的代码:
$activities = Activity::whereRaw('Date(created_at) as date',$date)->get();
dd($activities);
但是我得到一个错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'as date' at line 1 (SQL: select * from
activities
where Date(created_at) as date)
请帮我解决这个问题。这是 $date
的 dd()
:
"2019-12-12"
最佳答案
然后去:
$activities = Activity::whereDate('created_at', $date)
->get();
请记住,$date 必须采用日期格式。 检查https://laravel.com/docs/5.8/queries#where-clauses供引用。
关于php - 如何使用 laravel Raw 查询选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59325173/