F
Filamentβ€’9mo 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
7 Replies
Solution
LeandroFerreira
LeandroFerreiraβ€’9mo 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
ButterflyOPβ€’9mo ago
that worked! really appreciate the help πŸ˜„
Renan Pereira
Renan Pereiraβ€’3mo ago
Hi, how can I pass the instance of the record as a parameter. Say I wanted to passar the current record as title
LeandroFerreira
LeandroFerreiraβ€’3mo ago
If you want to access the record, I think you can use {{ $getRecord() }}
Renan Pereira
Renan Pereiraβ€’3mo ago
As I want to reuse this column, I prefer to pass it as a parameter. In the TextColumn I can use formatStateUsing(fn ($record) => $record)
awcodes
awcodesβ€’3mo ago
$getRecord() will work by default in any custom column. No need to pass it.
Renan Pereira
Renan Pereiraβ€’3mo ago
After a lot of digging, I had to do it in the view of my component, so in the end you have a $getTitle() for it to work. Probably because of the evaluate function that handles the data.
Want results from more Discord servers?
Add your server