Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiple where clause on Eloquent ORM Laravel?

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();
like image 717
jake balba Avatar asked Nov 25 '14 06:11

jake balba


2 Answers

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.

like image 100
sectus Avatar answered Nov 04 '22 17:11

sectus


As an addition to @sectus's answer, you might like this syntax:

$testq= DB::table('attendances')->whereUserId($userinput)
                                ->whereLogon($newdate)
                                ->get();
like image 42
TheBurgerShot Avatar answered Nov 04 '22 18:11

TheBurgerShot