F
Filament15mo ago
MRBUG

Relation on text area form?

i have a text area which is getting the relation from message model and i am currently in direct message modal so how can i get the data in our form and edit the message i created the form but i am getting the i of the message how can i do that ? Tables\Columns\TextColumn::make('message.content') ->sortable() ->toggleable(isToggledHiddenByDefault: false) ->searchable() ->label('Message Content')->limit(50),
No description
Solution:
You can, just specify with ->model(Event::class) like ```php Select::make('event_type_id') ->model(Event::class)...
Jump to solution
13 Replies
Altffenser
Altffenser15mo ago
To understand a little better, do you want to get the content of the message and not the ID?
MRBUG
MRBUGOP15mo ago
yes @Altffenser in my table column it's working fine but in form it is getting id because it is in relation
public function message()
{
return $this->belongsTo(Message::class, 'message_id');
}
public function message()
{
return $this->belongsTo(Message::class, 'message_id');
}
like that and in this message i have a field named content which is i called in the column. like that message.content
Altffenser
Altffenser15mo ago
Could you share the code of your table to have a little more context?
MRBUG
MRBUGOP15mo ago
firstly
Forms\Components\Textarea::make('message_id')
->required(),
Forms\Components\Textarea::make('message_id')
->required(),
i was using this which result is on given image and currently i am using this
Forms\Components\Select::make('message_id')
->relationship('message', 'content')->disableOptionWhen('id')
->required()->searchable()->editOptionForm([
Forms\Components\Textarea::make('content')->required(),
]),
Forms\Components\Select::make('message_id')
->relationship('message', 'content')->disableOptionWhen('id')
->required()->searchable()->editOptionForm([
Forms\Components\Textarea::make('content')->required(),
]),
but i want a textarea not select form.
MRBUG
MRBUGOP15mo ago
my current approach is that
No description
MRBUG
MRBUGOP15mo ago
@Altffenser is this approach is good or i should use textarea ?
Altffenser
Altffenser15mo ago
It is not, I was able to do it with textarea without any problem. It may help to specify the model.
Select::make('event_type_id')
->relationship('type', 'name')
->required()
->searchable()
->editOptionForm([
Textarea::make('name')
->label('Name')
->nullable()
->rules('required'),
TextInput::make('color')
->label('Color')
->type('color')
->required()
])
->required()
->rules('required'),
Select::make('event_type_id')
->relationship('type', 'name')
->required()
->searchable()
->editOptionForm([
Textarea::make('name')
->label('Name')
->nullable()
->rules('required'),
TextInput::make('color')
->label('Color')
->type('color')
->required()
])
->required()
->rules('required'),
Altffenser
Altffenser15mo ago
No description
Altffenser
Altffenser15mo ago
and specify the model with ->form({})->model(Event::class)
MRBUG
MRBUGOP15mo ago
we can not do it directly? like that in form
Forms\Components\Textarea::make('message.content')
->required(),
Forms\Components\Textarea::make('message.content')
->required(),
? yeah it is also working for me. but my question is that can we use relation directly to the textarea. insted of select form
Solution
Altffenser
Altffenser15mo ago
You can, just specify with ->model(Event::class) like
Select::make('event_type_id')
->model(Event::class)
->relationship('type', 'name')
->searchable()
->editOptionForm([
TextInput::make('name')
->label('Name')
->required()
->rules('required'),
TextInput::make('color')
->label('Color')
->type('color')
->required()
])
Select::make('event_type_id')
->model(Event::class)
->relationship('type', 'name')
->searchable()
->editOptionForm([
TextInput::make('name')
->label('Name')
->required()
->rules('required'),
TextInput::make('color')
->label('Color')
->type('color')
->required()
])
Altffenser
Altffenser15mo ago
This way above works too
MRBUG
MRBUGOP15mo ago
Okay, thanks.now I understand. I really appreciate it thank you .

Did you find this page helpful?