Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

laravel return number and boolean as string

in prod version laravel return number and boolean as string !!

Localhost :

{ "age": 24, "is_admin": 0, }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Prod :

{ "age": "24", "is_admin": "0", }

enter image description here

>Solution :

you can use Attribute Casting, it provides functionality similar to accessors and mutators without requiring you to define any additional methods on your model. Instead, your model’s $casts property provides a convenient method of converting attributes to common data types.

class MyModel extends Model
{
protected $casts = ['age' => 'integer','is_admin' => 'boolean'];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading