Skip to content
Advertisement

Laravel, how to ignore an accessor

I have a model with a custom accessor so I get that custom attribute,

JavaScript

But now, in one case, I need to get only some fields, without this OrderContents one.

JavaScript

But doing it this way, it returns me the OrderContents as well.. is there a way to not get that field?

Thanks!

Advertisement

Answer

There’s no way to do it in one go, so here’s what you need:

JavaScript

Alternatively, you may use Laravel’s Higher Order Messaging on the last step:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement