Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent

I've got a model for product, and a model for a sale - the product has a price, and the sale has start and end dates, and a modifier (e.g. reduce by 10%)

I can $appends a sale_price to my Product model that will pick up if the current product is in a sale. What I would prefer to do is overwrite the Product's price attribute with the calculated sale price if we know we're in a sale. So instead of, for example:

{
    "price": "14.99",
    "sale_price": "13.49"
}

I want the sale_price to override the product price so we just have:

{
    "price": "13.49"
}

Is this possible?

Last updated 2 years ago.
0

Thanks :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

MikkyX mikkyx Joined 10 May 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.