F
Filamentβ€’16mo ago
alcmz

Custom Page title changes by following the passed value

I'm trying to change the $title to be displaying by following the passed value please note that the passed value is in integer product_id , then we can refer back to the relationship which is product.name . As an example: View Product Details - [passedvaluehere] becomes, View Product Details - Product1 this is my code:

class ViewProductDetails extends Page implements Tables\Contracts\HasTable
{
use Tables\Concerns\InteractsWithTable;

protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static ?string $title = 'View Product Details ';
protected static string $view = 'filament.pages.view-product-details';


protected function getTableQuery(): Builder
{
$productId = request()->route('product');
return Tradingprofile::where('product_id', $productId);
}

protected function getTableColumns(): array

{
return [
TextColumn::make('customer.name')->label('Customer Name')->searchable(),

];
}

protected static function shouldRegisterNavigation(): bool
{
return false;
}

class ViewProductDetails extends Page implements Tables\Contracts\HasTable
{
use Tables\Concerns\InteractsWithTable;

protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static ?string $title = 'View Product Details ';
protected static string $view = 'filament.pages.view-product-details';


protected function getTableQuery(): Builder
{
$productId = request()->route('product');
return Tradingprofile::where('product_id', $productId);
}

protected function getTableColumns(): array

{
return [
TextColumn::make('customer.name')->label('Customer Name')->searchable(),

];
}

protected static function shouldRegisterNavigation(): bool
{
return false;
}
Is there any way to hide from the id appears on the link above instead display the product name.
Solution:
Something like this : ```php class ViewProduct extends ViewRecord { // ......
Jump to solution
4 Replies
alcmz
alcmzOPβ€’16mo ago
Please ignore the last question i've made it worked ! but i still not sure how do i modify the $title to be following the fetched product name
Solution
Patrick Boivin
Patrick Boivinβ€’16mo ago
Something like this :
class ViewProduct extends ViewRecord
{
// ...

protected function getTitle(): string
{
return 'Product:' . $this->record->name;
}
class ViewProduct extends ViewRecord
{
// ...

protected function getTitle(): string
{
return 'Product:' . $this->record->name;
}
Patrick Boivin
Patrick Boivinβ€’16mo ago
This looks like a custom page though, so you may not have access to $this->record... but you get the idea πŸ˜„
alcmz
alcmzOPβ€’16mo ago
Thanks Bud! got it worked! @pboivin
Want results from more Discord servers?
Add your server