modal doesn't save

I have this modal it shows the content i want but doesn't save the changes: Section::make('Bibliography') ->relationship('bibliography') ->schema([
Actions::make([ Action::make('modal_edit_with_data') ->mountUsing(function (Forms\ComponentContainer $form, Bibliography $record) { $data = []; // Get all data in array $dataRecord = $record->toArray(); // Save in $data by key = value foreach ($dataRecord as $key => $value) { $data[$key] = $value; } // Get all translations in array and save in $data by key = value foreach ($record->getTranslationsArray() as $key => $value) { $data[$key] = $value; } // Filled your data to $form and return return $form->fill($data); }) ->form([ Tabs::make('lang form') ->tabs([ Tabs\Tab::make('En') ->schema([ Forms\Components\RichEditor::make('en.text') ]), Tabs\Tab::make('Es') ->schema([ Forms\Components\RichEditor::make('es.text')
]), Tabs\Tab::make('Pt') ->schema([ Forms\Components\RichEditor::make('pt.text') ]),
]), ]),])->Columns('full'),]),
No description
27 Replies
cheesegrits
cheesegrits13mo ago
You aren't doing anything with the filled form.
Action::make('modal_edit_with_data')
//
->action(function (Model $record, array $data) {
// do whatever you need to do with the form data
}
)
Action::make('modal_edit_with_data')
//
->action(function (Model $record, array $data) {
// do whatever you need to do with the form data
}
)
I'm not sure what you are actually trying to do, and you need to tell Filament what to do when you build a custom action. t's not psychic.
MoisesSegura
MoisesSeguraOP13mo ago
I added this: ->action(function (array $data): void { $this->record->save(); }) but it still doesn't work.
Vp
Vp13mo ago
->action(function (array $data): void {
Model::create($data);
})
->action(function (array $data): void {
Model::create($data);
})
cheesegrits
cheesegrits13mo ago
What about explaining what you are actually trying to achieve?
MoisesSegura
MoisesSeguraOP13mo ago
The thing is that I have a resource "product detail" this product detail is associated with a "bibliography" these have translations and I need to show this information within the resourceProduct. When I try to add it in the normal way the content appears empty that's why I'm trying to load it in the modal which works but it doesn't save the changes
cheesegrits
cheesegrits13mo ago
What normal way have you tried?
MoisesSegura
MoisesSeguraOP13mo ago
the one that appears in the documentation Fieldset::make('Metadata') ->relationship('metadata') ->schema([ TextInput::make('title'), Textarea::make('description'), FileUpload::make('image'), ]) https://filamentphp.com/docs/3.x/panels/resources/relation-managers
cheesegrits
cheesegrits13mo ago
Paste your metadata relationship from the ProductDetail (or whatever it is) model. We need to see your actual code, not examples straight out of the docs.
MoisesSegura
MoisesSeguraOP13mo ago
Section::make('Bibliography') ->relationship('bibliography') ->schema([
Tabs::make('lang form') ->tabs([ Tabs\Tab::make('En') ->schema([ Forms\Components\RichEditor::make('en.text') ]), Tabs\Tab::make('Es') ->schema([ Forms\Components\RichEditor::make('es.text')
]), Tabs\Tab::make('Pt') ->schema([ Forms\Components\RichEditor::make('pt.text') ]), ]), ])->Columns('full'), something like that? as I said it appears empty, but may the problem is my translation package
No description
cheesegrits
cheesegrits13mo ago
OK, so now paste the 'bibliography' relationship from your main model.
MoisesSegura
MoisesSeguraOP13mo ago
sorry i dont get it
cheesegrits
cheesegrits13mo ago
The main model that your form is on, you said ProductDetail (or something like that). That model should have a relationship on it called 'bibiography', something like ...
public function bibliography()
{
// return relationship
}
public function bibliography()
{
// return relationship
}
MoisesSegura
MoisesSeguraOP13mo ago
public function bibliography() { return $this->belongsTo(Bibliography::class); } oh yes, but where do I paste it?
cheesegrits
cheesegrits13mo ago
Here. So I can see it. OK. So you have a bibliography_id foreign key on your ProductDetail table, yes? And what does the bibliography table look like. What fields does it have.
MoisesSegura
MoisesSeguraOP13mo ago
only text but its associated with a translation table CREATE TABLE bibliography ( id int(11) NOT NULL AUTO_INCREMENT, hide_locale varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=347 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE bibliography_translation ( id int(11) NOT NULL AUTO_INCREMENT, translatable_id int(11) NOT NULL, text longtext COLLATE utf8_unicode_ci NOT NULL, locale varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (id), UNIQUE KEY bibliography_translation_uniq_trans (translatable_id,locale), KEY IDX_CDE13E762C2AC5D3 (translatable_id), CONSTRAINT FK_CDE13E762C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES bibliography (id) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=539 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
cheesegrits
cheesegrits13mo ago
OK, so what's the relationship (in Laravel terms) between bibliography and bibliography_translation? Is it a HasMany or a MorphMany?
MoisesSegura
MoisesSeguraOP13mo ago
it doesn't have one tha package (astrotomic) handles it class Bibliography extends Model implements TranslatableContract { use HasFactory; use Translatable; protected $table = 'bibliography'; protected $guarded = []; public $translatedAttributes = ['text']; public $timestamps = false; }
cheesegrits
cheesegrits13mo ago
I suspect that interface (Contract) implements a relationship. So take a look at the Translatable trait. My bet is there a 'translations' relationship in the trait, probably MorphMany.
MoisesSegura
MoisesSeguraOP13mo ago
trait Translatable { // This override get translations fields protected function fillForm(): void { $this->callHook('beforeFill'); $data = $this->getRecord()->attributesToArray(); foreach (static::getRecord()->getTranslationsArray() as $key => $value) { $data[$key] = $value; } $data = $this->mutateFormDataBeforeFill($data); $this->form->fill($data); $this->callHook('afterFill'); } // This override get SQL optimization and get all translations protected function getTableQuery(): Builder { return static::getResource()::getEloquentQuery()->with('translations'); } }
cheesegrits
cheesegrits13mo ago
GitHub
GitHub - Astrotomic/laravel-translatable: A Laravel package for mul...
A Laravel package for multilingual models. Contribute to Astrotomic/laravel-translatable development by creating an account on GitHub.
MoisesSegura
MoisesSeguraOP13mo ago
yes that is
cheesegrits
cheesegrits13mo ago
OK, so the Contract does implement a translations() HasMany (I was wrong, it's not a MorphMany). https://github.com/Astrotomic/laravel-translatable/blob/main/src/Translatable/Contracts/Translatable.php#L49
GitHub
laravel-translatable/src/Translatable/Contracts/Translatable.php at...
A Laravel package for multilingual models. Contribute to Astrotomic/laravel-translatable development by creating an account on GitHub.
cheesegrits
cheesegrits13mo ago
OK, so your relationship "chain" from your ProductDetail model is bibliography -> translations. I've never tried nested relationships in Filament, but you could try ...
Group::make()
->relationship('bibliography')
->schema([
Repeater::make('translations')
->relationship('translations')
->schema([
TextInput::make('locale'),
Textarea::make('text'),
]),
]),
Group::make()
->relationship('bibliography')
->schema([
Repeater::make('translations')
->relationship('translations')
->schema([
TextInput::make('locale'),
Textarea::make('text'),
]),
]),
See if that works.
MoisesSegura
MoisesSeguraOP13mo ago
OMG it worked! thanks man!
cheesegrits
cheesegrits13mo ago
Filament is literally black magic voodoo, you just have to figure out the right incantations.
MoisesSegura
MoisesSeguraOP13mo ago
so it's not psychic but it's magical xD
cheesegrits
cheesegrits13mo ago
It is close to becoming sentient.
Want results from more Discord servers?
Add your server