Laravel - Query Builder - Where Clauses

You may use the query builder's where method to add "where" clauses to the query. The most basic call to the where method requires three arguments. The first argument is the name of the column. The second argument is an operator, which can be any of the database's supported operators. The third argument is the value to compare against the column's value.

For example, the following query retrieves users where the value of the votes column is equal to 100 and the value of the age column is greater than 35:

    
    $users = DB::table('users')
                    ->where('votes', '=', 100)
                    ->where('age', '>', 35)
                    ->get();
	

For convenience, if you want to verify that a column is = to a given value, you may pass the value as the second argument to the where method. Laravel will assume you would like to use the = operator:

    
    $users = DB::table('users')->where('votes', 100)->get();
	

As previously mentioned, you may use any operator that is supported by your database system:

    
    $users = DB::table('users')
                    ->where('votes', '>=', 100)
                    ->get();
    
    $users = DB::table('users')
                    ->where('votes', '<>', 100)
                    ->get();
    
    $users = DB::table('users')
                    ->where('name', 'like', 'T%')
                    ->get();
	

You may also pass an array of conditions to the where function. Each element of the array should be an array containing the three arguments typically passed to the where method:

    
    $users = DB::table('users')->where([
        ['status', '=', '1'],
        ['subscribed', '<>', '1'],
    ])->get();
	
PDO does not support binding column names. Therefore, you should never allow user input to dictate the column names referenced by your queries, including "order by" columns.