F
Filamentβ€’2y ago
ericmp

how to pass in parameters into custom column

in my custom column i have a text and an image sometimes, i want to show first the image, then the text sometimes, i want to show first the text, then the img is there a way to achieve this passing a param to my custom column?
protected function getTableColumns(): array
{
return [
MyCustomColumn::make('custom'),
protected function getTableColumns(): array
{
return [
MyCustomColumn::make('custom'),
5 Replies
Patrick Boivin
Patrick Boivinβ€’2y ago
Something like this in your custom column class :
class MyColumn extends Column
{
protected bool $imageFirst = false;

public function imageFirst(bool $value): self
{
$this->imageFirst = $value;

return $this;
}

public function getImageFirst(): bool
{
return $this->imageFirst;
}

// ...
class MyColumn extends Column
{
protected bool $imageFirst = false;

public function imageFirst(bool $value): self
{
$this->imageFirst = $value;

return $this;
}

public function getImageFirst(): bool
{
return $this->imageFirst;
}

// ...
Then you should be able to set the option from the resource or table config :
MyCustomColumn::make('custom')->imageFirst(true)
MyCustomColumn::make('custom')->imageFirst(true)
and get it in your Blade view :
@if ($getImageFirst())
...
@endif
@if ($getImageFirst())
...
@endif
ericmp
ericmpOPβ€’2y ago
that is awesome is there any documentation on this in filamentphp docs? id like to learn more bout it @pboivin
Patrick Boivin
Patrick Boivinβ€’2y ago
I don't remember seeing this in the docs, I was just digging in the source code of the built-in columns to see how it works.
ericmp
ericmpOPβ€’2y ago
i think i should do it too then thanks again!!
Patrick Boivin
Patrick Boivinβ€’2y ago
You're welcome πŸ™Œ
Want results from more Discord servers?
Add your server