I want filter product by gender(men,women) gender of product saved in database inwith json format like ["\u0622\u0642\u0627\u06cc\u0627\u0646"]
in my controller want get product by gender name
public function index(){
$product = Product::where(['gender' => json_decode('men',true)])
->orderBy('created_at','Desc')->
get();
}
how can fetch product that gender is men or women Some products can be used for both men and women, so I save in Json format
dd from product as you can see gender store in json format:
thanks a lot for your help
CodePudding user response:
The problem is that in the database you wrote in persian, but in the controller you wrote in english. I would suggest to save this data in english into your database, but if it is not an option try this:
$product = Product::whereIn('gender', ['man-in-persian-language','woman-in-persian-language'] )
->orderBy('created_at','Desc')
->get();
Also I dont know how many genders you have in your projects, but if there is only 'man' and 'woman' then there is no need to query for gender, and you will get al products which gender is man or woman.
CodePudding user response:
dd from product as you can see gender store in json format