The where
clause queries a database.
In this shot, we will learn to use the where()
query builder to query the database. This is an important and basic concept while writing a query in Laravel.
where()
methodThe where()
method is a query builder that queries an instance of a data table from a database to get specific row(s) from it.
DB::table('users')->where('votes', '>', 100)->get();
The where()
method accepts basically three parameters;
There is an existing shot on table() method you can look at it for more understanding.
The where()
query builder finds a query value match on the database’s column name. It does so to contain or filter down either the result or the return value.
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
From the example above, the database has been updated. We use the where()
query builder to locate and update a specific cell on a table’s row. Hence, the row with an id of one on the user’s table has been updated. Specifically, the votes column of that record is updated to 1.
RELATED TAGS
CONTRIBUTOR
View all Courses