How to add multiple where clause on Eloquent ORM Laravel?
36,293
Solution 1
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
$this where(string $column, string $operator = null, mixed $value = null, string $boolean = 'and')
Add a basic where clause to the query.
Solution 2
As an addition to @sectus's answer, you might like this syntax:
$testq= DB::table('attendances')->whereUserId($userinput)
->whereLogon($newdate)
->get();
Author by
jake balba
Updated on December 02, 2020Comments
-
jake balba over 3 years
Having a hard time here trying to retrieve specific records where I need the ID and the Date to match, here is my code:
$testq= DB::table('attendances')->where('user_id', '=', $userinput && 'logon', '=', $newdate)->get();
-
jake balba over 9 yearsexcuse me for asking you one more, but can you tell me how to use if statement and determine if the record exist? 'if($testq exists)' ?
-
sectus over 9 years@jakebalba, you could check $testq->count() laravel.com/api/4.2/Illuminate/Database/Eloquent/…
-
jake balba over 9 yearsso it will be like this ? 'if ($testq->count()<1)' sorry newbie here
-
sectus over 9 years@jakebalba, you have wrote the code - do not ask - test it. Test takes less time than asking : )
-
sectus over 9 years@jakebalba, add one more question with your code and attemps
-
jake balba over 9 yearsStill have another problem sir, I think the code is just using 'OR' and not 'AND'
-
sectus over 9 years@jakebalba, stackoverflow.com/questions/16995102/…
-
Pathros about 8 yearsHow about when you want to retrieve all the values (and including
NULL
) except one. In My case I don't get theNULL
rows. For example,->where('country_id','!=',120)
But I don't get theNULL
values. How do I fix this? -> I just found out by adding->orWhereNull('country_id')
;)