@vincent15000 @povilaskorop I did change the database structure as per your suggestion. I got a list of products having categories by the whereHas() clause.
now seems I'll still have a problem as I have a field named "is_finish" = "yes/no" for the respective category.
if "is_finish = no", the finish_time field will be stored a null. if "yes", whatever time.
Cases:
- ) The product with a category having is_finish = no, that product always will keep in the result list (Here I do not have to check the "finish_time < whatevertime" )
- ) The Product list with a category having the is_finish = yes, that product will disappear from the list after whatever time of created_at. (Here I do need to check the "finish_time < whatevertime")
- ) category and their finish_time will be dynamic
Query:
Product::whereHas('categories', function($query) {
$query->where('is_finish', 'yes'/'no'); // if yes then check finish_time, if no then keep product into the list
$query->where('created_at', '>=', Carbon::now()->addMinutes($whatever_finish_time_of_X_category)); // $whatever_finish_time_of_X_category >> stores in DB table "categoty"
});
what should I do with these cases, If I want to manage with a single query, is it possible?
plus what is the best way to manage the below scenario,
$query->where('created_at', '>=', Carbon::now()->addMinutes($whatever_finish_time_of_X_category)); // $whatever_finish_time_of_X_category >> stores in DB table "category"
if Category = kitchen, then finish_time will be $whatever_finish_time_of_X_category
if Category = clothes then finish_time will be $whatever_finish_time_of_X_category
if Category = XYZ, then the finish time will be $whatever_finish_time_of_X_category
and so on...
I'm getting deeper and more confused than seems I guess :(
Edit:
or Should I just go with the case like, managing the "finish_time" with the product table while storing?
and fetch those product whose expire_time < now() or something? if yes, then what is a better way to store non-expire category product time in a table?
Many Thanks!