Performance: Where clauses
Where clauses affect database query speed and the time it takes to fetch data, impacting page load and interaction responsiveness.
$users = DB::table('users')->where('status', 'active')->get();
$users = DB::table('users')->get()->where('status', 'active');
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Filtering after fetching all data | N/A | N/A | High due to slow data arrival | [X] Bad |
| Filtering in database query with where clause | N/A | N/A | Low due to fast data arrival | [OK] Good |
where clause do in a Laravel query?where clausewhere clause is used to filter database records by specifying conditions.where.Product::where('price', '>', 100)->where('stock', '>=', 10)->get();User::where('status', 'active')->get();$isAdmin that is true or false.when method allows adding conditions only if a boolean is true.when correctly to add where clauses only if $isAdmin is true. Order::where('status', 'completed')->where('total', '>', 500)->get(); always applies filters. Order::if($isAdmin)->where('status', 'completed')->where('total', '>', 500)->get(); uses invalid if method. Order::where('status', 'completed' && $isAdmin)->where('total', '>', 500)->get(); has wrong syntax mixing boolean and string.Pass the test and this pattern moves unknown