I have two queries I will like to re-write.
The first one is a raw query I would like to re-write using eloquent
DB::select('select * from asks WHERE amount IN (select MIN(amount) as lowest_ask from `asks` where `product_uuid` = ? group by `shoe_size_id`)', [$this->uuid]);
This gets the lowest ask for each shoe size if you need some context.
I tried many iterations but it all failed, here is the last one I did tried
Ask::where('amount', function($query) use ($product_id) {
$query->select([
DB::raw('MIN(amount) as lowest_ask'),
])
->where('product_uuid', $product_id)
->groupBy('shoe_size_id')
->get();
});
but it did not work
The second is a regular whereHasquery on a polymorphic many to many relationship.
$products->whereHas('brand', function ($query) use ($request) {
$query->where('name', $request->get('brand'));
});
I will love to re-write this using a join. I have made several attempts but could not.
Thanks for the help