I did this:
foreach(Product::all() as $product) {
if ($product->isPaid()) {
$products[] = $product;
}
}
But idk if is the best way, there is another way to do that?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
For example, i have a method in my model to check if the Product is paid.
public function isPaid()
{
return $this->getRemainingValue() <= 0 && ($this->value != null);
}
How can i iterate over all registers and get only the models that "is paid" but using this method, without writing a new query. Something like iterate over all registers and return all models that are true using isPaid method.
Please or to participate in this conversation.