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 returned7 Replies
How should i handle this situation? $ record comes in the mount method as a string
Is this your full code of the class? Did you declare a method getRecord?
Yes, this is the complete class code
define
public Ticket $record
then you dont need $ticket either
just $this->record
or $this->getRecord()
Oh ok got it. Thank you
I have tried to define it but it throws a different error
okay i see what you did wrong
remove $record and mount() completely
thats all you should need