Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0
Solution

http://laravel.com/docs/eloquent#accessors-and-mutators

I think this is one way to do it? Grab your attribute name, and then typecast the return value, or do some logic to change the output.

Last updated 2 years ago.
0
Last updated 2 years ago.
0

It's actually very simple. Say you have a column named 'status' in your table. In your model, add this method:

public function getStatusAttribute($status)
{
    return (bool) $status;
}

Ehesp has provided the URL for the docs.

Last updated 2 years ago.
0

Thanks for the responses!

Casting in the getters worked for me.

Last updated 2 years 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.