F
Filamentβ€’3mo ago
Butterfly

Passing props to a custom column

I have the following custom column
@props(['title', 'subtitle'])

<div>
<div class="flex items-center">
<div class="ml-2.5 truncate flex flex-col text-left">
<div class="text-sm font-medium truncate text-foreground">
{{ $title }}
</div>

<div class="text-xs truncate text-muted-foreground">
{{ $subtitle }}
</div>
</div>
</div>
</div>
@props(['title', 'subtitle'])

<div>
<div class="flex items-center">
<div class="ml-2.5 truncate flex flex-col text-left">
<div class="text-sm font-medium truncate text-foreground">
{{ $title }}
</div>

<div class="text-xs truncate text-muted-foreground">
{{ $subtitle }}
</div>
</div>
</div>
</div>
Is there a way to pass the props from the resource?
MediaObjectColumn::make('avatar_url')
->label('Avatar')

MediaObjectColumn::make('avatar_url')
->label('Avatar')

Solution:
add in your MediaObjectColumn class ```php protected string|Closure|null $title = null; ...
Jump to solution
2 Replies
Solution
LeandroFerreira
LeandroFerreiraβ€’3mo ago
add in your MediaObjectColumn class
protected string|Closure|null $title = null;

public function title(string|Closure|null $title): static
{
$this->title = $title;

return $this;
}

public function getTitle(): ?string
{
return $this->evaluate($this->title);
}
protected string|Closure|null $title = null;

public function title(string|Closure|null $title): static
{
$this->title = $title;

return $this;
}

public function getTitle(): ?string
{
return $this->evaluate($this->title);
}
MediaObjectColumn::make('avatar_url')
->label('Avatar')
->title('Custom title')
MediaObjectColumn::make('avatar_url')
->label('Avatar')
->title('Custom title')
in the view
{{ $getTitle() }}
{{ $getTitle() }}
Butterfly
Butterflyβ€’3mo ago
that worked! really appreciate the help πŸ˜„