Models

Introduction

All models in the Streams Platform eventually extends Laravel's Eloquent models. This documentation will assume you are already familiar with Laravel models.

Base Models

All models in the Streams Platform will extend the base \Anomaly\Streams\Platform\Model\EloquentModel class and therefore will have a number of basic features unique to the Streams Platform.

Entry Models

Entry models are specific to the streams API. Not all models are entry models but all entry models extend base models.

Hooks

All models are Hookable.

Translatable

All models support translation. Though all models may not be translatable.

Check Translatable

You can use the isTranslatable method to check if a model is translatable.

if ($entry->isTranslatable()) {
    echo "Yes!";
}
{% if entry.isTranslatable() %}
    Yes!
{% endif %}

### Translating Queries

Please see [query builder](../database/query-builder) documentation.

### Translating Entries

You can use the `translate` method to return the translation of a given `locale` with optional `withFallback`.

> This is only necessary if non-active locale values are desired.{.tip}

```php
$entry->translate($locale = null, $withFallback = false);

echo $entry->translate('fr', true)->name;
{{ entry->translate('fr', true).name }}

All Translations

You can return a collection of translations with the getTranslations method.

foreach ($entry->getTranslations() as $translation) {
    echo "{$translation->name} ({$translation->locale})";
}
{% for translation in entry.getTranslations() %}
    {{ translation.name }} ({{ translation.locale }})
{% endfor %}