FilamentF
Filament3y ago
14 replies
Albert Lens

Errors in Select with new field Attribute appended to eloquent model

Hello.
I need a bunch of appended fields to several of my models. I have followed the normal Laravel usage for this:

I define the accessor and add Attribute in model:
protected $appends = ['my_new_field'];
    
public function getMyNewFieldAttribute()
{
    return $this->name . ' ' . $this->doc_num;
}


And then I want to use it in my Select field like this:
Select::make('decedent_id')
    ->preload()
    ->relationship('decedent', 'my_new_field')
    ->label(__('decedent_id_title'))
    ->options(Person::where('enabled',true)->where('type','causante')->pluck('my_new_field', 'id'))


And I get the error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'my_new_field' in 'field list'

I have checked using Tinker and it works fine.
Any idea of what can be happening?
Tks.
Was this page helpful?