shandias
Please Help - Form Action
class Settings extends Page implements HasForms
{
use InteractsWithForms;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.settings';
public function mount()
{
$companyDetails = CompanyDetail::find(1);
$this->form->fill([
'company_name' => $companyDetails->company_name ?? '',
'address' => $companyDetails->address ?? '',
'telephone' => $companyDetails->telephone ?? '',
'email' => $companyDetails->email ?? '',
]);
}
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('company_name')
->label('Company Name')
->required(),
Textarea::make('address')
->label('Company Address')
->required(),
TextInput::make('telephone')
->label('Tel No.')
->tel()
->telRegex('/^[+][(]{0,1}[0-9]{1,4}[)]{0,1}[-\s./0-9]$/')
->required()
->reactive(),
TextInput::make('email')
->label('E-mail')
->email()
->required(),
]);
}
public function getFormActions()
{
Action::make('save')
->label('Save Settings')
->submit('save')
->color('primary');
}
public function save() { // Get form data $data = $this->form->getState();
CompanyDetail::updateOrCreate( ['id' => 1], $data ); session()->flash('success', 'Settings have been saved successfully!'); } } Error TypeError count(): Argument #1 ($value) must be of type Countable|array, null given
public function save() { // Get form data $data = $this->form->getState();
CompanyDetail::updateOrCreate( ['id' => 1], $data ); session()->flash('success', 'Settings have been saved successfully!'); } } Error TypeError count(): Argument #1 ($value) must be of type Countable|array, null given
5 replies