27 lines
595 B
PHP
27 lines
595 B
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use Spatie\Translatable\HasTranslations as BaseHasTranslations;
|
|
|
|
trait HasTranslations
|
|
{
|
|
use BaseHasTranslations;
|
|
|
|
/**
|
|
* Convert the model instance to an array.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function toArray()
|
|
{
|
|
$attributes = parent::toArray();
|
|
foreach ($this->getTranslatableAttributes() as $field) {
|
|
$attributes[$field] = $this->getTranslation($field, \App::getLocale());
|
|
$attributes[$field.'_translations'] = $this->getTranslations($field);
|
|
}
|
|
|
|
return $attributes;
|
|
}
|
|
}
|