columns dynamic inside table
I try to use the dynamic columns defintion for the table.
For example i use tabs :
public function getTabs(): array
{
return [
'Tab1' => ListRecords\Tab::make()->label('Tab1')
->modifyQueryUsing(fn (Builder $query) =>
$query->whereIn('status', [1, 2, 3])),
'Draft' => ListRecords\Tab::make()
->modifyQueryUsing(fn (Builder $query) =>
$query->where('status', 4)),
];
}
public function getTabs(): array
{
return [
'Tab1' => ListRecords\Tab::make()->label('Tab1')
->modifyQueryUsing(fn (Builder $query) =>
$query->whereIn('status', [1, 2, 3])),
'Draft' => ListRecords\Tab::make()
->modifyQueryUsing(fn (Builder $query) =>
$query->where('status', 4)),
];
}
public static function table(Table $table): Table
{
$activeTab = $table->getLivewire()->activeTab;
$tableReturn = null;
switch ($activeTab) {
case 'Tab2':
$tableReturn = self::tableTab2($table);
break;
case 'Tab1':
$tableReturn = self::tableDefault($table);
break;
}
return $tableReturn;
}
public static function table(Table $table): Table
{
$activeTab = $table->getLivewire()->activeTab;
$tableReturn = null;
switch ($activeTab) {
case 'Tab2':
$tableReturn = self::tableTab2($table);
break;
case 'Tab1':
$tableReturn = self::tableDefault($table);
break;
}
return $tableReturn;
}
public static function tableDefault(Table $table): Table
{
return $table
->columns([]);
}
public static function tableDefault(Table $table): Table
{
return $table
->columns([]);
}
0 Replies