Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\MergeValue;
use Illuminate\Support\Str;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Http\Controllers\ResourceIndexController;
use Laravel\Nova\Http\Controllers\FieldAttachmentController;
use Spatie\NovaTranslatable\Exceptions\InvalidConfiguration;

class Translatable extends MergeValue
Expand Down Expand Up @@ -165,6 +167,20 @@ protected function createTranslatableFields()
return;
}

if ($this->isFieldAttachmentRequest(request())) {
collect($this->locales)
->crossJoin($this->originalFields)
->eachSpread(function (string $locale, Field $field) {
$translatedField = clone $field;
$translatedField->attribute = 'translations_'.$translatedField->attribute.'_'.$locale;

$this->data[] = $translatedField;
$this->translatedFieldsByLocale[$locale][] = $translatedField;
});

return;
}

$this->data = [];

collect($this->locales)
Expand Down Expand Up @@ -237,4 +253,15 @@ protected function onIndexPage(): bool

return $currentController === ResourceIndexController::class;
}

protected function isFieldAttachmentRequest(Request $request): bool
{
if (! $request->route()) {
return false;
}

$currentController = Str::before(request()->route()->getAction()['controller'] ?? '', '@');

return $currentController === FieldAttachmentController::class;
}
}