Im building ecommerce website and i want to ask what is the best way to search specifications of product.I have a field in database with specification that can be stored as json or as php array.Is there any tutorial that i can use to output unique specification for example category CPU, and to put different CPU brands under that category so user can decide which specification to add to search filter.To give you a perspective i want to make something like this
Advertisement
Answer
You could search though whereJsonContains()
method.
for example;
let assume there are some filter in your form as below
brands - intel - amd Number of core - 2 - 4 - 8
Now let build a query to get filtered results
Cpu::whereJsonContains("preferences->brand",$request->brand) ->whereJsonContains("preferences->noc", $request->noc) ->get();
But I’m not sure if storing such a json data in your database is a good practice. Because it’s not store and display case, there will generic results depends those specifications.