Closed jaulz closed 5 months ago
@spawnia Hi, this breaks when Models have native Enum casted attributes. $model->getOriginal()
casts the attributes. json_encode($relatedModel->getOriginal())
will then fail because enums are not stringable. Can we just use $model->getRawOriginal()
?
Hm, the best would actually be to pick $original
from the model but it's protected.
That would be $model->getRawOriginal()
@skaesdorf great, can you raise a PR for that?
@jaulz Done. See #2550
Changes
Right now,
toJson
is used which "is recursive, so all attributes and relations will be converted to JSON" (see https://laravel.com/docs/11.x/eloquent-serialization#serializing-to-json). This means that all accessors are executed as well which can affect the performance of an application. The new approach simply compares the raw attributes of the models which should be enough in almost all cases as far as I can see.Breaking changes
There might be a tiny chance that something doesn't work as before because accessors are not compared anymore.