---
title: "Serialization — Translatable for Laravel | Roundly"
description: "toArray(), toJson(), JSON responses and API Resources emit each attribute’s resolved locale value, not the raw map."
url: https://roundly-consulting.com/open-source/docs/translatable-for-laravel/serialization
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Translatable for Laravel](https://roundly-consulting.com/open-source/docs/translatable-for-laravel.md)

# Serialization

toArray(), toJson(), response()->json($model) and API Resources emit the resolved locale value for each translatable attribute — identical to $model->name — not the raw stored JSON map:

```php
app()->setLocale('en');

$topic->toArray()['name'];   // "Investing"  (localized, through the fallback chain)
$topic->toJson();            // {"name":"Investing", …}
TopicResource::make($topic); // {"name":"Investing"}
response()->json($topic);    // same resolved values
```

The effective FallbackMode is honoured: a model in None mode with only sk set serializes name as null for an en request. Persisted data is untouched — this changes output shape only.

## Exposing the full map

When an admin screen needs every locale, call getTranslations() explicitly — for example in a dedicated resource:

```php
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

final class AdminTopicResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->getTranslations('name'),           // ['en' => '…', 'sk' => '…']
            'missing' => $this->missingTranslations(),          // field => missing locales
            'completeness' => $this->translationCompleteness(), // 0.0–1.0
        ];
    }
}
```

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/translatable-for-laravel.md)
