Fill custom edit page form with data

 <?php

namespace App\Filament\Resources\LearningCategoryResource\Pages;

use Filament\Forms\Form;
use App\Models\LearningResource;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\EditRecord;
use App\Filament\Resources\LearningCategoryResource;
use Filament\Resources\Pages\Concerns\InteractsWithRecord;

class CustomEditResource extends EditRecord
{
    use InteractsWithRecord;

    protected static string $resource = LearningCategoryResource::class;

    public function mount(int | string $record): void
    {
        $this->record = LearningResource::findOrFail($record);
    }

    public function form(Form $form): Form
    {
        return $form
            ->columns(12)
            ->schema([
                Section::make('Resource information')
                    ->columnSpan(12)
                    ->columns(12)
                    ->schema([
                        TextInput::make('name')
                            ->label('Name')
                            ->required()
                            ->columnSpan(10),
                    ]),
            ]);
    }
}
I have created a filament page, selected EditPage when filament asked me what kind of page is this going to be and now I am trying to fill the form with $record data, but I dont understand how to do that. Can someone help? This is a custom edit page for a relationManager, not a resource itself, so in a $resource and a mount function I have a different models.
Solution
You can access your form using the mount() method. From there, you should be able to fill the fields with your record in this way:

public function mount(int | string $record): void
{
        $this->record = LearningResource::findOrFail($record);
        $this->fillForm();
}
Was this page helpful?