php - 如何使用 laravel Raw 查询选择行

标签 php mysql laravel

我想从我的事件表中选择给定日期的所有行。为此,我使用了 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)

请帮我解决这个问题。这是 $datedd():

"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/

相关文章:

c# - EF Code First 使用现有的 MySql 数据库

Laravel 限制每个模型的急切加载

javascript - 即使使用 $_SERVER 全局,PHP header 也总是给出错误“未定义索引”

php - 如何关闭 postgres 中的多个语句?

MySQL tz_convert utc 返回空值?

mysql - 更新具有不同条件的多行

php - 仅当字符串不为空/空时如何解密字符串

php - 调用未定义的方法 Symfony\Component\HttpFoundation\Response::header()

php - Codeigniter:将查询结果存入关联数组

php - Symfony2 - 关于 php 错误和 404 的空白页