Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

Use the $appends attribute.

http://laravel.com/docs/eloquent#converting-to-arrays-or-json

See the link and scroll down up to the bottom page to see how it works.

Basically, what this thing does is it creates a custom attribute to your model. You will create a getter for that attribute and put the logic there. Then in your view, you can just fetch the attribute.

Other answers other than this is welcome. I'm also interested if there are other ways to do it besides this.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2024 Laravel.io - All rights reserved.