dani94
7 months ago
1702
2
Tips

Any pretty solution for this?

Posted 7 months ago by dani94

I have Order Model, which has products relationship and products have category relationship. I need to get a function in my model to get single product with a static category.

Im doing the next code in Order.php, my model, but i dont like it.

‚Äč`` public function mainProduct() { foreach ($this->products as $product) if ($product->category_id == 1) return $product; }

Please sign in or create an account to participate in this conversation.