Rick Doetinchem
Enum, select and relationship
I have two tables. The first table, orders contains a relationship to the table products. Under the table products, the status of the product is stored as 1 = in stock, 2 = out of stock, 3 = no longer available. An enum is used to convert the integer 1, 2 or 3 into a label. This works fine in the products resource , but how can I get this done in the orders resource? There I now have a select field which shows the values 1, 2 or 3 based on the relationship. But I want to extract the integer values from the relationship and then use the enum to convert the values to labels. How do you do that with a select in combination with a relationship?
3 replies
Routes in Filament
It seems that routes in filament are stored decentrally in the vendor files. I find them with php artisan route:list. But how to create a workable situation with this? Isn't it much more convenient to define the routes in web.php? Does anyone know where I can find documentation about this? I have not found it on the filament website.
3 replies
Fetch relational data in custom page
How can I fetch the relational data in personable.full_name?
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')
->autofocus()
->required(),
TextInput::make('personable.full_name')
->required(),
])
->statePath('data')
->model($this->ticket);
}
public Ticket $ticket;
public function mount(int | string $record): void
{
$this->ticket = Ticket::findOrFail($record);
$this->form->fill($this->ticket->attributesToArray());
}
User.php model:
public function tickets(): MorphMany
{
return $this->morphMany(Ticket::class, 'personable');
}
Ticket.php model:
public function personable(): MorphTo
{
return $this->morphTo();
}
8 replies
Custom page with resource record error
I have a custom page:
public static function getPages(): array
{
return [
'ticketWithComments' => Pages\TicketWithComments::route('/{ticketId}/ticketwithcomments'),
…
];
}
And I try to pickup the ticketId and fill the form with the following code:
public function mount($ticketId): void
{
$this->ticket = Ticket::findOrFail($ticketId);
$this->form->fill($this->ticket->attributesToArray());
}
But I’m getting error: Typed property App\Filament\App\Resources\TicketResource\Pages\TicketWithComments::$ticket must not be accessed before initialization
What am I doing wrong?21 replies