1

What I'm trying to do is an affiliate program and I wish when I call an scope it returns all my desired values. There will be a logic for calculation of the values for the platform, seller and affiliate.

What I have already is:

public function scopeProfitPlatform($query) {
    return $query->sum('price')*0.6;
}

public function scopeProfitAffiliate($query) {
    return $query->sum('price')*0.05;
}

public function scopeProfitBuyer($query) {
    return $query->sum('price')*0.35;
}

This works, however I'd like to make this more simple. So instead of having to call Order::profitplatform() and order::profitaffiliate, etc.... I wanted to call Order::profit() and it would return all those values to me all at once.

I tried to use Order::profitplatform()->profitaffiliate() but it doesn't work.

I was thinking of creating a specific service for this purpose however I don't think it's necessary. I think it's possible to with scopes or something else similar, however I'm not finding the solution.

I appreciate any suggestions, ideas and solutions for simplifying this problem. Thanks.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
hamon
  • 103
  • 3
  • 9

1 Answers1

1

try this:

Order::profitplatform()->profitaffiliate()->get();