0

is there any reason eloquent $casts wouldnt be working?

I am storing json, json column type, and

protected $casts = [
    'fields' => 'array'
];

But..

\App\Lead::find(1)->fields

still returns json

"{"first_name":"Brian","last_name":"Dillingham","email":"[email protected]"}"

Doesn't even work when I mutate

public function getFieldsAttribute($value)
{
    return json_decode($value, true);
}

But works when I

dd(json_decode(\App\Lead::find(1)->fields, true));
1
  • I think its because I am manually storing the json in a text field, sorry cant delete the question Commented Nov 15, 2016 at 18:45

1 Answer 1

1

Just type cast it from your mutator function:

public function getFieldsAttribute($value)
{
    return (array) json_decode($value, true);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.