F
Filamentβ€’2y ago
Pasteko

How do you call a relation attribute in form?

public function getFullNameAttribute()
{
return ucfirst($this->first_name) . ' ' . ucfirst($this->last_name);
}
public function getFullNameAttribute()
{
return ucfirst($this->first_name) . ' ' . ucfirst($this->last_name);
}
In table I just call : customer.full_name I know it's not possible that way but can't make it work.
Forms\Components\Group::make()
->relationship('customer')
->schema([
Forms\Components\TextInput::make('full_name')->disabled(),
]),
Forms\Components\Group::make()
->relationship('customer')
->schema([
Forms\Components\TextInput::make('full_name')->disabled(),
]),
11 Replies
Dan Harrin
Dan Harrinβ€’2y ago
Placeholder::make('full_name')->content(fn ($record) => $record->full_name)
Placeholder::make('full_name')->content(fn ($record) => $record->full_name)
Pasteko
PastekoOPβ€’2y ago
Thanks, it works. But finally it's better if I use this :
Forms\Components\Select::make('customer_id')
->relationship('customer', 'last_name')
->searchable(['last_name', 'first_name'])
->label('Client')
->required(),
Forms\Components\Select::make('customer_id')
->relationship('customer', 'last_name')
->searchable(['last_name', 'first_name'])
->label('Client')
->required(),
The problem is now how can I use this "full_name" attribute here?
Dan Harrin
Dan Harrinβ€’2y ago
->getOptionLabelFromRecord(fn ($record) => $record->full_name)
Pasteko
PastekoOPβ€’2y ago
It gives me a type error : Filament\Forms\Components\Select::getOptionLabelFromRecord(): Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, Closure given, called in C:\laragon\www\adm.ap\app\Filament\Resources\OrderResource.php on line 35
Dan Harrin
Dan Harrinβ€’2y ago
sorry ->getOptionLabelFromRecordUsing(fn ($record) => $record->full_name)
Pasteko
PastekoOPβ€’2y ago
Thanks, it's very helpful for me πŸ™‚
Pasteko
PastekoOPβ€’2y ago
There's just something strange now, when I search, it appends the default value to the bottom of the search.
Dan Harrin
Dan Harrinβ€’2y ago
thats just the way it works, you didnt do anything wrong
Pasteko
PastekoOPβ€’2y ago
it's in the case you click the delete value on the right?
Dan Harrin
Dan Harrinβ€’2y ago
so you can keep the current value selected
Pasteko
PastekoOPβ€’2y ago
πŸ™
Want results from more Discord servers?
Add your server