THY
THY
FFilament
Created by THY on 12/2/2024 in #❓┊help
Getting filament to use my own getLabel() implementation
The Filament\Tables\Columns\Column uses the Concerns\HasLabel trait. Inside this trait, there is a method named getLabel() I would like to customize it a little bit. First, I duplicated the original HasLabel.php to put it under app/Filament/Tables/Columns/Concerns project folder and customize the getLabel() method to just return a test string:
namespace App\Filament\Tables\Columns\Concerns;

use Closure;
use Illuminate\Contracts\Support\Htmlable;

trait HasLabel
{
/* skipped original codes here for brevity */

// Then this is my own version of getLabel()
public function getLabel(): string|Htmlable
{
return 'test';
}
}
namespace App\Filament\Tables\Columns\Concerns;

use Closure;
use Illuminate\Contracts\Support\Htmlable;

trait HasLabel
{
/* skipped original codes here for brevity */

// Then this is my own version of getLabel()
public function getLabel(): string|Htmlable
{
return 'test';
}
}
Then I created the Column.php file under app\Filament\Tables\Columns\Column with the following codes to, extends from the original one and make it use my own version of HasLabel trait:
namespace App\Filament\Tables\Columns;

use App\Filament\Tables\Columns\Concerns\HasLabel;

class Column extends \Filament\Tables\Columns\Column
{
use HasLabel;
}
namespace App\Filament\Tables\Columns;

use App\Filament\Tables\Columns\Concerns\HasLabel;

class Column extends \Filament\Tables\Columns\Column
{
use HasLabel;
}
Next is adding the class binding in the AppServiceProvider:
public function register(): void
{
$this->app->bind(\Filament\Tables\Columns\Column\Column::class, \App\Filament\Tables\Columns\Column::class);
}
public function register(): void
{
$this->app->bind(\Filament\Tables\Columns\Column\Column::class, \App\Filament\Tables\Columns\Column::class);
}
Finally, I ran these commands to make sure the changes are known by both Laravel and Filament:
sail composer dump-autoload
sail artisan optimize:clear
sail artisan filament:optimize-clear
sail composer dump-autoload
sail artisan optimize:clear
sail artisan filament:optimize-clear
Unfortunately, I still don't get the label output "test". Filament does not seem to be using my version of Column class and HasLabel trait at all. It's still using its own ones. Why can't they be discovered?
2 replies