Laravel数据以特定的值显示,并且特定值具有特定日期?
我在表中有类似此
ID | 名称 | 状态 | 创建的数据create_at |
---|---|---|---|
1 | ABC | 1 | 2022-01-01 |
2 | ABC | 2 | 2022-01-01 |
3 | XXD | 3 | 2022-01-01 |
5 | ABC | 3 | 2022-01-01 |
6 | JON | 5 | 2022-01--01--01--01--01- 01 |
7 | WER | 5 | 2022-06-01 |
8 | ABC | 5 | 2022-06-01 |
,我想要这样的结果。我想显示数据,如果status> = 2,但是如果状态= 5,我只想显示, create_at> = 2022-06-06-01 and name ='
abc'ID | 名称 | 状态 | 创建_at |
---|---|---|---|
2 | ABC | 2 | 2022-01-01 |
3 | ABC | 3 | 2022-01-01 |
7 | ABC | 5 | 2022-06-01 |
我在SQL中尝试过下面
WHERE name='ABC' and status BETWEEN 3 AND 4 OR status > 5 OR
(status = 5 AND created_at >= '2022-01-01');
它在SQL中起作用,并按照预期显示。但是我对如何在Laravel控制器中使用它感到困惑。它仍然显示所有数据。
我试了
$query= TABLE::where('status','>=','3')->where('status','<=','4')->orWhere('status','5'5)->where('created_at','>=','2022-01-01)->where('name','ABC')->get();
事先感谢你。
I have data in table like this
id | name | status | created_at |
---|---|---|---|
1 | ABC | 1 | 2022-01-01 |
2 | ABC | 2 | 2022-01-01 |
3 | XXD | 3 | 2022-01-01 |
5 | ABC | 3 | 2022-01-01 |
6 | JON | 5 | 2022-01-01 |
7 | WER | 5 | 2022-06-01 |
8 | ABC | 5 | 2022-06-01 |
And I want results like this. I want to show data if status >= 2, but if status = 5, I only want to show, data with created_at >=2022-06-01 AND NAME='ABC'
id | name | status | created_at |
---|---|---|---|
2 | ABC | 2 | 2022-01-01 |
3 | ABC | 3 | 2022-01-01 |
7 | ABC | 5 | 2022-06-01 |
I tried in SQL like below
WHERE name='ABC' and status BETWEEN 3 AND 4 OR status > 5 OR
(status = 5 AND created_at >= '2022-01-01');
It works in SQL, and show as per expected. But I am confused on how to use it in Laravel controller. It still shows all data.
I tried
$query= TABLE::where('status','>=','3')->where('status','<=','4')->orWhere('status','5'5)->where('created_at','>=','2022-01-01)->where('name','ABC')->get();
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将其称为:
这将承认具有2到4的状态值,严格大于5或等于5,在2022年6月1日或之后创建的记录。
您的Laravel代码可能看起来像:
I would phrase this as:
This admits records having a status value from 2 to 4, strictly greater than 5, or equal to 5 with a created at date on or after June 1, 2022.
Your Laravel code might look like:
据我所知,您希望所有具有2-4个状态的数据,并且是否状态为5,而不是检查 create_at&gt; = 2022-06-01和name ='abc'。
As I understand that you want all data with status between 2-4 and if status is 5 than check if created_at >=2022-06-01 AND NAME='ABC'.