FilamentF
Filament2y ago
Sydd

getRecordTitleAttribute from related model

Dear all, last time I have a lot of question. Please how can I create record title attibute from realated mode? for getGloballySearchableAttributes it works fine, but for getRecordTitleAttribute; in the Filament docs I read that it's must be a column / attributefrom model ... but is possible to get from related model ?
public static function getRecordTitleAttribute(): ?string
    {
        return 'user.fullName'; //not working
    }

    public static function getGloballySearchableAttributes(): array
    {
        return ['user.fullName']; // working fine
    }
Solution
This would go on your edit and view page classes. Not on the resource.

use Illuminate\Contracts\Support\Htmlable;
 
public function getTitle(): string | Htmlable
{
    return $this->record->user->fullName;
}
Was this page helpful?