Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jvespa's avatar

Save from modal to another table

Hello, i am new at Laravel/Filament, i have facing an issue, so please i am asking for help.

I have two related models: Canal and Link Canals can has many links.

In the CanalResource, i need add a button/action to add links to the selected Canal, so i think that the best user experience, could be a modal that let me add as many links as he want to that channel.

So reading about it i create a new action:

​``` Tables\Actions\Action::make('links')

                                        ->label('Links')
                                        ->color('success')
                                        ->icon('heroicon-o-link')
                                        ->form([
                                            Forms\Components\TextInput::make('link_canal')
                                                ->label('Agregar Link')
                                                ->placeholder('Inserte el link')
                                        ])
                                        /*->action(function (Canal $record, array $data): void {
                                            $record->descripcion_canal=$data['descripcion_canal'];
                                            $record->save();
                                            Notification::make()
                                            ->title('cambiado')
                                            ->body('ok')
                                            ->color('success')
                                            ->send();
                                        }),*/
                                        ->action(function (Link $record): void {
                                            $record->url_link='www.google.com';
                                            $record->prioridad_link=1;
                                            $record->estado_link='activo';
                                            $record->save();
                                        }),

The commented code works, because is the same model that used in the resource (i guess), but i want to save the form to another table/model, i am not sure if this is the way.

BTW the resource use the second model:

use App\Models\Link;
Both models has the relationsip:
    public function links(): HasMany
    {
        return $this->hasMany(Link::class);
    }

The error is:

TypeError App\Filament\Resources\CanalResource::App\Filament\Resources{closure}(): Argument #1 ($record) must be of type App\Models\Link, App\Models\Canal given, called in /home2/readylyg/desarrollo.readybo.com/laravel/adminlistas/vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35

I hope you can understand and help me.

Thanks you.

0 likes
0 replies

Please or to participate in this conversation.