Undefined property: App\Filament\Pages\SettingsPage::$form

class SettingsPage extends Page implements HasForms
{

use InteractsWithForms;

protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';

protected static string $view = 'filament.pages.settings-page';

public ?array $data = [];

public function mount(): void
{
$settings = ModelsSettings::first() ?? new ModelsSettings();
$this->form->fill($settings->toArray());
}

public function form(Form $form): Form
{
return $form
->schema([
.....
])
->statePath('data')
->model(ModelsSettings::class);
}

protected function getFormActions(): array
{
return [
Action::make('save')
->label('Save')
->submit('save'),
];
}

public function save()
{
$data = $this->form->getState();
dd($data);
$settings = ModelsSettings::first() ?? new ModelsSettings();
$settings->fill($data);
$settings->save();

Notification::make()
->title('Settings saved successfully')
->success()
->send();
}


}
class SettingsPage extends Page implements HasForms
{

use InteractsWithForms;

protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';

protected static string $view = 'filament.pages.settings-page';

public ?array $data = [];

public function mount(): void
{
$settings = ModelsSettings::first() ?? new ModelsSettings();
$this->form->fill($settings->toArray());
}

public function form(Form $form): Form
{
return $form
->schema([
.....
])
->statePath('data')
->model(ModelsSettings::class);
}

protected function getFormActions(): array
{
return [
Action::make('save')
->label('Save')
->submit('save'),
];
}

public function save()
{
$data = $this->form->getState();
dd($data);
$settings = ModelsSettings::first() ?? new ModelsSettings();
$settings->fill($data);
$settings->save();

Notification::make()
->title('Settings saved successfully')
->success()
->send();
}


}
i need to understand why it doesn't work before a solution, because i've set the form already so what is making filamentphp not recognizing it , any help is appreciated
Solution:
for some reason just refreshing the page solved the problem lol got no idea what happen
Jump to solution
2 Replies
toeknee
toeknee4mo ago
Add parent::mount(); to the top of your mount.
Solution
影の人
影の人4mo ago
for some reason just refreshing the page solved the problem lol got no idea what happen

Did you find this page helpful?