PHP code example of fnx-software / filament-astrotomic
1. Go to this page and download the library: Download fnx-software/filament-astrotomic library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fnx-software / filament-astrotomic example snippets
// app/Providers/Filament/AdminPanelProvider.php
use Fnxsoftware\FilamentAstrotomic\FilamentAstrotomicPlugin;
use Filament\Panel;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugins([
FilamentAstrotomicPlugin::make(),
]);
}
// app/Models/Post.php
use Illuminate\Database\Eloquent\Model;
use Astrotomic\Translatable\Contracts\Translatable as TranslatableContract;
use Astrotomic\Translatable\Translatable;
class Post extends Model implements TranslatableContract
{
use Translatable;
public array $translatedAttributes = ['title', 'content'];
protected $fillable = ['author_id'];
}
// app/Filament/Resources/PostResource.php
use Fnxsoftware\FilamentAstrotomic\Resources\Concerns\ResourceTranslatable;
use Filament\Resources\Resource;
class PostResource extends Resource
{
use ResourceTranslatable;
// ...
}
// app/Filament/Resources/PostResource/Pages/ListPosts.php
use Fnxsoftware\FilamentAstrotomic\Resources\Pages\ListTranslatable;
use Filament\Resources\Pages\ListRecords;
class ListPosts extends ListRecords
{
use ListTranslatable;
// ...
}
// app/Filament/Resources/PostResource/Pages/CreatePost.php
use Fnxsoftware\FilamentAstrotomic\Resources\Pages\CreateTranslatable;
use Filament\Resources\Pages\CreateRecord;
class CreatePost extends CreateRecord
{
use CreateTranslatable;
// ...
}
// app/Filament/Resources/PostResource/Pages/EditPost.php
use Fnxsoftware\FilamentAstrotomic\Resources\Pages\EditTranslatable;
use Filament\Resources\Pages\EditRecord;
class EditPost extends EditRecord
{
use EditTranslatable;
// ...
}
// app/Filament/Resources/PostResource/Pages/ViewPost.php
use Fnxsoftware\FilamentAstrotomic\Resources\Pages\ViewTranslatable;
use Filament\Resources\Pages\ViewRecord;
class ViewPost extends ViewRecord
{
use ViewTranslatable;
// ...
}
use Fnxsoftware\FilamentAstrotomic\Schemas\Components\TranslatableTabs;
use Fnxsoftware\FilamentAstrotomic\TranslatableTab;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Form;
public static function form(Form $form): Form
{
return $form->schema([
TranslatableTabs::make()
->localeTabSchema(fn (TranslatableTab $tab) => [
TextInput::make($tab->makeName('title'))
->
use Fnxsoftware\FilamentAstrotomic\Schemas\Components\TranslatableTabs;
use Fnxsoftware\FilamentAstrotomic\TranslatableTab;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
TranslatableTabs::make()
->localeTabSchema(fn (TranslatableTab $tab) => [
TextInput::make($tab->makeName('title'))
// Renders label as "Title (English)"
->label($tab->makePrefixLabel('Title')),
Textarea::make($tab->makeName('description'))
// Renders label as "(English) Description"
->label($tab->makeSuffixLabel('Description')),
])
use Fnxsoftware\FilamentAstrotomic\Schemas\Components\TranslatableTabs;
use Fnxsoftware\FilamentAstrotomic\TranslatableTab;
use Filament\Forms\Components\TextInput;
TranslatableTabs::make()
->customLocales(['ar', 'en', 'fr', 'pt'])
->localeTabSchema(fn (TranslatableTab $tab) => [
TextInput::make($tab->makeName('label'))
->
use Fnxsoftware\FilamentAstrotomic\Forms\Components\TranslatableSelect;
use Filament\Forms\Form;
public static function form(Form $form): Form
{
return $form->schema([
// ... other fields
TranslatableSelect::make('country_id')
->translatableRelationship('country', 'name')
->searchable()
->preload()
->label('Country')
->
// In your List page (e.g., ListPosts.php)
use Fnxsoftware\FilamentAstrotomic\Actions\LocaleSwitcher;
use Filament\Actions\CreateAction;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
LocaleSwitcher::make(), // Add this
];
}
// In your Table definition
use Fnxsoftware\FilamentAstrotomic\Tables\Columns\TranslatableColumn;
use Filament\Tables\Table;
public static function table(Table $table): Table
{
return $table
->columns([
TranslatableColumn::make('title')
->searchable()
->sortable(),
// ... other columns
]);
}
// In your Infolist definition
use Fnxsoftware\FilamentAstrotomic\Infolists\Components\TranslatableEntry;
use Filament\Infolists\Infolist;
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
TranslatableEntry::make('title'),
TranslatableEntry::make('content'),
// ... other entries
]);
}
use Fnxsoftware\FilamentAstrotomic\FilamentAstrotomicPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
FilamentAstrotomicPlugin::make()
->force() // Always show tabs
);
}
use Fnxsoftware\FilamentAstrotomic\Schemas\Components\TranslatableTabs;
TranslatableTabs::make('translations')
->force() // Always show tabs for this specific component
->localeTabSchema(fn (TranslatableTab $tab) => [
// ...
])
use Fnxsoftware\FilamentAstrotomic\Actions\LocaleSwitcher;
// Pass a list of locale codes (labels generated automatically)
LocaleSwitcher::make()
->locales(['en', 'fr']);
// Or pass custom labels
LocaleSwitcher::make()
->locales([
'en' => 'English (US)',
'fr' => 'Français (France)',
]);
public static function getTranslatableLocales(): array
{
return ['en', 'fr'];
}
use App\Models\Post;
use Filament\Tables\Actions\EditAction;
->actions([
EditAction::make()->mutateRecordDataUsing(function (Post $record, array $data) {
return static::mutateTranslatableData($record, $data);
}),
])
// In your GovernorateResource table
TranslatableColumn::make('country.name')
->label('Country')
->searchable()
->sortable(),
// In your GovernorateResource infolist
TranslatableEntry::make('country.name')
->label('Country'),