How to create a query with multiple WHERE conditions in Laravel Eloquent?
Hi everyone! I'm new to Laravel and trying to figure out how to build complex database queries. I have a `products` table, and I need to select products by multiple conditions simultaneously. For example, I want to find all products where `status = 'active'`, `price > 100` and `category_id = 5`. In regular SQL I would write something like:
```sql
SELECT * FROM products WHERE status = 'active' AND price > 100 AND category_id = 5;
```
But how do I do this with Eloquent? I tried this code:
```php
$products = Product::where('status', 'active')
->where('price', '>', 100)
->where('category_id', 5)
->get();
```
It works, but it doesn't seem quite right, especially when there are many conditions. Also I heard
No answers yet.
Log in to leave an answer