Dynamic page title throws error

Hello, I'm trying to set a dynamic page title. Unfortunately when the mount method executes it throws an error related to the getRecord() method. <?php namespace App\Filament\Resources\TicketResource\Pages; use App\Models\Ticket; use Filament\Pages\Actions; use Filament\Resources\Pages\ViewRecord; use App\Filament\Resources\TicketResource; class ViewTicket extends ViewRecord { protected static string $resource = TicketResource::class; protected static string $view = 'filament.resources.tickets.pages.view-ticket'; protected static ?string $title = 'Ticket n.' ; public function mount($record): void { $ticket = Ticket::find($record); $this->number = $ticket->number; // Imposta il titolo dinamicamente ViewTicket::$title = "Ticket n.{$this->number}"; } protected function getActions(): array { return [ // ]; } } This is the code that I'm using and this is the error that I'm getting but I don't understand why, the error in my opinion comes from ($ticket=Ticket::find($record)): Filament\Resources\Pages\ViewRecord::getRecord(): Return value must be of type Illuminate\Database\Eloquent\Model, string returned
7 Replies
Gianmarco Varrone
How should i handle this situation? $ record comes in the mount method as a string
wyChoong
wyChoong2y ago
Is this your full code of the class? Did you declare a method getRecord?
Gianmarco Varrone
Yes, this is the complete class code
Dan Harrin
Dan Harrin2y ago
define public Ticket $record then you dont need $ticket either just $this->record or $this->getRecord()
Gianmarco Varrone
Oh ok got it. Thank you
Gianmarco Varrone
I have tried to define it but it throws a different error
Dan Harrin
Dan Harrin2y ago
okay i see what you did wrong remove $record and mount() completely
protected function getTitle(): string
{
return "Ticket n.{$this->record->number}";
}
protected function getTitle(): string
{
return "Ticket n.{$this->record->number}";
}
thats all you should need
Want results from more Discord servers?
Add your server