mercredi 30 mars 2022

Correct setup for a Laravel resource of a jsonb column?

I have a jsonb column in Postgres that I'm trying to make use of with Laravel. When the resource itself is returned (rest, etc), the value for that column is returned null:

{
    "content": [
        {
            "partner_uuid": "bc844aa7-283e-4b82-8188-2f8764bc9d59",
            "metadata": null
        }
    ]
}

From the backend, this row definitely is non-null:

bc844aa7-283e-4b82-8188-2f8764bc9d59 | {"test": "test"}

I'm not very familiar with Laravel, and so I'm struggling a bit. The problem seems to be in the resource itself, which has a single function:

class PartnerMetadataResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            'partner_uuid' => $this->partner_uuid,
            'metadata' => $this->metadata,
        ];
    }
}

If the metadata column is any other column type, this code seems sufficient to return the value as expected. I've tested with integers, text/varchar (and even the other column which is type uuid).

What is needed to return a value for that column? Either as escaped text, or as proper nested json?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/y47J6hE
via IFTTT

Aucun commentaire:

Enregistrer un commentaire