How to use where in two condition on blade laravel

Solution:1

you can use where condition in laravel blade as you can use them in your controller

({{ \App\Product::all()->where(‘category_id’,$category->id)->where(‘user_id’,Auth::user()->id)->count() }})

Solution:2

You can chain multiple where’s after each other.

({{ \App\Product::where('category_id', $category->id)->where('user_id', Auth::user()->id)->count() }})

My suggestion is you read the query builder documentation, it explains everything you can do quite well.


I also noticed you started your query with a all() this will retrieve all rows from the database running those where conditions in your app. It’s faster to run them on your database so by removing all() the query will be run with those where conditions as I think is what you want.