php 如何在 Eloquent ORM Laravel 上添加多个 where 子句?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27120324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add multiple where clause on Eloquent ORM Laravel?
提问by jake balba
Having a hard time here trying to retrieve specific records where I need the ID and the Date to match, here is my code:
在这里尝试检索需要 ID 和日期匹配的特定记录时很难,这是我的代码:
$testq= DB::table('attendances')->where('user_id', '=', $userinput && 'logon', '=', $newdate)->get();
采纳答案by sectus
Just add one more where.
只需在此处再添加一个。
$testq= DB::table('attendances')
->where('user_id', '=', $userinput)
->where('logon', '=', $newdate)
->get();
http://laravel.com/api/4.2/Illuminate/Database/Eloquent/Builder.html#method_where
http://laravel.com/api/4.2/Illuminate/Database/Eloquent/Builder.html#method_where
$this where(string $column, string $operator = null, mixed $value = null, string $boolean = 'and')
Add a basic where clause to the query.
$this where(string $column, string $operator = null, mix $value = null, string $boolean = 'and')
向查询添加一个基本的 where 子句。
回答by TheBurgerShot
As an addition to @sectus's answer, you might like this syntax:
作为@sectus 答案的补充,您可能会喜欢以下语法:
$testq= DB::table('attendances')->whereUserId($userinput)
->whereLogon($newdate)
->get();