Hi all,
Imagine we need to compute stats about an Eloquent model. Those stats would be stored in the $attributes property of the model and would be computed leveraging real db Eloquent attributes of this model and of its relationships. I highlight the fact that those stats are not stored in db, i.e.: there is NO db column for them (that's why I would use $attributes property, along with a getter/setter method).
Moreover, we want to add several scope Eloquent methods that would fetch the Eloquent models for which those stats are equal / greater than / lower than / etc. than the other models of this same PHP class.
- One way to do that is:
- To write again the computation we did in the
getter/settersmethods for stats we wrote along with the$attributesproperty, but in SQL, in the scope functions.
- To write again the computation we did in the
- Another way to do that is:
- I don't know, that's the goal of this topic. Do you know how to avoid to re-write the PHP logic in SQL please? I would want to re-use the code returning the statistics in both scopes functions AND
$attributesproperty getter/setter for stats.
Thank you in advance, best regards.
Jars.