F
Filament2mo ago
Iron

Display Model name on page title

So, i have tried for an hour or two now, figured i have to ask because i can find some info on getTitle() and getHeader and getHeading(), however, even if i do return $this->record->name It does not return it, if i dont have a null check i get error that name is null. I figured its because its not loaded yet, but i have tried everything now, whats the cleanest and bests way to just display the model name ( model of which we are editing right now ) as title of page? I did self::$title but that changed title on a lot of pages not just the particual one i am on.
Solution:
It's because you made the $record protected. I think Livewire only fills public properties.
Jump to solution
6 Replies
Dennis Koch
Dennis Koch2mo ago
I'd say it should work. Can you share your code?
Dennis Koch
Dennis Koch2mo ago
I just tested this with the v4 demo:
class EditOrder extends EditRecord
{
protected static string $resource = OrderResource::class;

public function getTitle(): string|Htmlable
{
return 'Record ' . $this->record->number;
}
class EditOrder extends EditRecord
{
protected static string $resource = OrderResource::class;

public function getTitle(): string|Htmlable
{
return 'Record ' . $this->record->number;
}
No description
Iron
IronOP2mo ago
Ahh well i am not extending EditRecord, my page is custom. Im not at work atm but looks something like class MyJob extends Page implements HasForms { use InteractsWithForms; protected string $view = 'filament.app.pages.jobs.my-job'; protected static ?string $slug = 'my-job/{record}'; protected ?Assignment $record = null; public int|string|null $recordId = null; public ?array $data = []; public string $activeTab = 'settings'; Then i have a mount method to load record relationships $this->record = $record->load('timesheets', 'client'); And then the getTitle method. Should also note that the page is working nicely, saving etc, just the name in title missing atm.
Solution
Dennis Koch
Dennis Koch2mo ago
It's because you made the $record protected. I think Livewire only fills public properties.
Iron
IronOP2mo ago
wow sorry man i was tired after a long day missed that xD it was the issue. Thank you for the quick responses.
Dennis Koch
Dennis Koch2mo ago
Had to test it myself, too. Not easy to spot 😅

Did you find this page helpful?