F
Filament14mo ago
ico

Filament v2 property null when searching

I have a filament table from a livewire component. Witch i want to make it be dynamic to work with different logic per table I have a mount() method that looks like:
protected ?Collection $tableProperty = null;

public function mount()
{
$this->tableProperty = DataTableInitializer::initialize($this->dataTableType);
$this->dataTableButtons = $this->tableProperty['dataTableButtons'];
}
protected ?Collection $tableProperty = null;

public function mount()
{
$this->tableProperty = DataTableInitializer::initialize($this->dataTableType);
$this->dataTableButtons = $this->tableProperty['dataTableButtons'];
}
and my methods look like this
protected function getTableQuery(): Builder
{
return $this->tableProperty['query'];
}
protected function getTableColumns(): array
{
return $this->tableProperty['columns'];
}

.
.
.
.
protected function getTableQuery(): Builder
{
return $this->tableProperty['query'];
}
protected function getTableColumns(): array
{
return $this->tableProperty['columns'];
}

.
.
.
.
But when i go to a next page or try to use the search i get that the tableProperty is null if i add the initialize of the tableProperty in each method everything is normal
protected function getTableQuery(): Builder
{
$this->tableProperty = DataTableInitializer::initialize($this->dataTableType);
return $this->tableProperty['query'];
}
protected function getTableColumns(): array
{
$this->tableProperty = DataTableInitializer::initialize($this->dataTableType);
return $this->tableProperty['columns'];
}
protected function getTableQuery(): Builder
{
$this->tableProperty = DataTableInitializer::initialize($this->dataTableType);
return $this->tableProperty['query'];
}
protected function getTableColumns(): array
{
$this->tableProperty = DataTableInitializer::initialize($this->dataTableType);
return $this->tableProperty['columns'];
}
But this does not look good in my opinion. So what must i do to escape this repeating and initialize the tableProperty just once ?
Solution:
To escape this repeating of code i added the hydrate hook in the livewire component This worked very well ```php public function mount()...
Jump to solution
1 Reply
Solution
ico
ico14mo ago
To escape this repeating of code i added the hydrate hook in the livewire component This worked very well
public function mount()
{
$this->tableProperty = DataTableInitializer::initialize($this->dataTableType);
$this->dataTableButtons = $this->tableProperty['dataTableButtons'];
}
public function hydrate()
{
// filament table loses its inner properties. So on each hydrate of the livewire component i must provide the initializing of the tableProperty
$this->tableProperty = DataTableInitializer::initialize($this->dataTableType);
$this->dataTableButtons = $this->tableProperty['dataTableButtons'];
}
public function mount()
{
$this->tableProperty = DataTableInitializer::initialize($this->dataTableType);
$this->dataTableButtons = $this->tableProperty['dataTableButtons'];
}
public function hydrate()
{
// filament table loses its inner properties. So on each hydrate of the livewire component i must provide the initializing of the tableProperty
$this->tableProperty = DataTableInitializer::initialize($this->dataTableType);
$this->dataTableButtons = $this->tableProperty['dataTableButtons'];
}
Want results from more Discord servers?
Add your server