<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
unusualdope / filament-model-translatable example snippets
use Unusualdope\FilamentModelTranslatable\FmtPlugin;
use Filament\Panel;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
FmtPlugin::make()
);
}
}
use Unusualdope\FilamentModelTranslatable\Models\FmtModel;
class Post extends FmtModel
{
//...
/**
* Translatable props needed
*/
protected $lang_model = 'App\Models\PostLanguage'; //fqn of the translatable model
protected $lang_foreign_key = 'post_id'; //foreign key
protected $is_translatable = true;
protected $translatable = [
'title' => [ //field name that will match with the LangModel db field and property
'formType' => 'TextInput', //The type of form input field as in Filament
'name' => 'Title', //Field Label
'methods' => [ //The methods you want to call from filament on your field to define it
'
self::addTranslatableFieldsToSchema(array $schema, Form $form, Bool false);
class PostResource extends Resource
{
use FmtModelTrait;
protected static ?string $model = Post::class;
protected static ?string $navigationIcon = 'heroicon-o-document-duplicate';
public static function form(Form $form): Form
{
$schema = [
Forms\Components\Select::make('user_id')
->relationship('user', 'name')
->searchable()
->