cactus-galaxy/filament-astrotomic
Installation
composer require cactus-galaxy/filament-astrotomic
Publish the config (if needed):
php artisan vendor:publish --provider="CactusGalaxy\FilamentAstrotomic\FilamentAstrotomicServiceProvider"
Prerequisites Ensure you have:
Translatable trait on your Eloquent models.First Use Case
Add the HasTranslations trait to a Filament resource:
use CactusGalaxy\FilamentAstrotomic\Concerns\HasTranslations;
class PostResource extends Resource
{
use HasTranslations;
// ...
}
This auto-generates translation fields for all translatable attributes.
Basic Translation Fields
The package auto-detects translatable attributes and renders them as Filament TextInput/RichEditor fields per locale.
// No manual field definition needed; handled by `HasTranslations`.
public static function form(Form $form): Form
{
return $form
->schema([
// Translations are auto-injected here.
]);
}
Customizing Translation Fields Override the default field types per attribute:
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')
->translatable(), // Explicitly mark as translatable
RichEditor::make('content')
->translatable()
->columnSpanFull(),
]);
}
Locale Management
config/filament-astrotomic.php (default_locale).config/app.php (locales) or override via:
public static function getLocales(): array
{
return ['en', 'es', 'fr'];
}
Bulk Locale Updates
Use the updateTranslations method in resource actions:
public static function getActions(PostResource $resource): array
{
return [
Action::make('update-translations')
->action(function (Post $record) {
$record->updateTranslations([
'en' => ['title' => 'New English Title'],
'es' => ['title' => 'Nuevo Título'],
]);
}),
];
}
Integration with Filament Tables Display translations in table columns:
Table::make([
TextColumn::make('title')
->translatable(), // Shows translations for the current locale
TextColumn::make('title.es') // Force a specific locale
->label('Spanish Title'),
]);
Fallback Locales
Configure fallback locales in config/filament-astrotomic.php:
'fallback_locales' => [
'en' => ['es', 'fr'], // Fallback for English
],
Locale Mismatch Errors
Undefined locale errors if config/app.php locales don’t match filament-astrotomic.php.locales in app.php include all locales used in translations.Missing Translatable Attributes
translatable array isn’t properly defined.Translatable trait and has:
protected $translatable = ['title', 'content'];
Caching Conflicts
php artisan filament:cache-reset
Nested Resource Conflicts
HasTranslations may conflict with nested resources.->ignoreTranslations() on specific fields.Log Translatable Attributes Add this to your model to debug:
protected static function booted()
{
\Log::info('Translatable attributes:', self::$translatable);
}
Check Database Structure
Verify the translations table exists and has the correct columns:
SELECT * FROM information_schema.columns
WHERE table_name = 'translations';
Override Default Behavior Disable auto-translation for specific fields:
public static function form(Form $form): Form
{
return $form->schema([
TextInput::make('non_translatable_field')
->ignoreTranslations(),
]);
}
Custom Field Types
Extend the package to support custom translatable fields (e.g., Select, Checkbox):
use CactusGalaxy\FilamentAstrotomic\Concerns\HasTranslations;
class CustomSelect extends Select
{
use HasTranslations;
}
Locale-Specific Validation Add locale-aware validation rules:
public static function getValidationRules(): array
{
return [
'title.en' => 'required|max:255',
'title.es' => 'required|max:255',
];
}
Translation History Integrate with Laravel Model Observers to log translation changes:
class PostObserver
{
public function saved(Post $post)
{
if ($post->wasChanged('translations')) {
\Log::info('Translations updated:', $post->getDirty());
}
}
}
API Resource Support Extend the package to support Filament API Resources for translation endpoints:
class PostApiResource extends ApiResource
{
public static function getTranslations(Post $record): array
{
return $record->getTranslations();
}
}
How can I help you explore Laravel packages today?