Home > OS >  laravel return number and boolean as string
laravel return number and boolean as string

Time:11-14

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

Localhost :

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

Prod :

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

enter image description here

CodePudding user response:

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'];

CodePudding user response:

Before sending data you can convert it to int or bool check out the following code -

$age = (int)$age;
$is_admin = (boolean);
  • Related