© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•17mo ago•
3 replies
CarbonNanotubes

Displaying Custom Model attributes in a table

Before I upgraded to V3 I was able to access my custom attribute by like so
TagColumn::make('triggers.definedName)
TagColumn::make('triggers.definedName)

but since upgrading this seems to no longer work.
TextColumn::make('triggers.definedName')
    ->badge(),
TextColumn::make('triggers.definedName')
    ->badge(),


Here is my attribute
    public function definedName(): Attribute
    {
        return Attribute::make(
            get: function (mixed $value, array $attribute) {
                if ($attribute['machine_status_id'] != null) {
                    return $attribute['line_status->name'];
                }

                if ($attribute['machine_state_id'] != null) {
                    return $attribute['machine_state->name'];
                }

                return $attribute['name'];
            }
        );
    }
    public function definedName(): Attribute
    {
        return Attribute::make(
            get: function (mixed $value, array $attribute) {
                if ($attribute['machine_status_id'] != null) {
                    return $attribute['line_status->name'];
                }

                if ($attribute['machine_state_id'] != null) {
                    return $attribute['machine_state->name'];
                }

                return $attribute['name'];
            }
        );
    }


I can access it in Tinker
$t = Trigger::first()
[!] Aliasing 'Trigger' to 'App\Models\Trigger' for this Tinker session.
= App\Models\Trigger {#7658
    id: "1",
    criteria: "max",
    value: "5",
    unit_of_measure: "parts",
    created_at: "2023-01-24 17:32:09.333",
    updated_at: "2023-12-11 16:33:13.657",
    machine_status_id: null,
    task_id: null,
    machine_state_id: null,
    name: "First Occurrence",
  }

> $t->definedName;
= "First Occurrence"
$t = Trigger::first()
[!] Aliasing 'Trigger' to 'App\Models\Trigger' for this Tinker session.
= App\Models\Trigger {#7658
    id: "1",
    criteria: "max",
    value: "5",
    unit_of_measure: "parts",
    created_at: "2023-01-24 17:32:09.333",
    updated_at: "2023-12-11 16:33:13.657",
    machine_status_id: null,
    task_id: null,
    machine_state_id: null,
    name: "First Occurrence",
  }

> $t->definedName;
= "First Occurrence"
Solution
Fixed it by changing my attribute to look like this
public function getDefinedNameAttribute()
    {
        if ($this->machine_status_id != null) {
            return $this->line_status->name;
        }

        if ($this->machine_state_id != null) {
            return $this->machine_state->name;
        }

        return $this->name;
    }
public function getDefinedNameAttribute()
    {
        if ($this->machine_status_id != null) {
            return $this->line_status->name;
        }

        if ($this->machine_state_id != null) {
            return $this->machine_state->name;
        }

        return $this->name;
    }


Also in the model

protected $appends = ['definedName'];
protected $appends = ['definedName'];
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Custom model attributes in model
FilamentFFilament / ❓┊help
2y ago
Building Custom Field That Requires 2 Model Attributes
FilamentFFilament / ❓┊help
2y ago
Show hidden model attributes
FilamentFFilament / ❓┊help
3y ago