form->fill( auth()->user()->attributesToArray() ); } public function form(Form $form): Form { return $form ->schema([ Section::make(__('General information'))->schema([ Hidden::make('user_id'), Select::make('nickname') ->translateLabel() ->options(NickNameEnum::class), TextInput::make('fname_ar') ->translateLabel() ->required() ->minLength(2) ->maxLength(64) ->rule(UserConstants::ARABIC_CHARACTERS_REGEX), TextInput::make('lname_ar') ->translateLabel() ->required() ->minLength(2) ->maxLength(64) ->rule(UserConstants::ARABIC_CHARACTERS_REGEX), TextInput::make('fa_name_ar') ->translateLabel() ->required() ->minLength(2) ->maxLength(64) ->rule(UserConstants::ARABIC_CHARACTERS_REGEX), TextInput::make('fname_en') ->label('First name') ->required() ->minLength(2) ->maxLength(64) ->rule(UserConstants::ENGLISH_ADDRESS_REGEX), TextInput::make('lname_en') ->label('Last name') ->required() ->minLength(2) ->maxLength(64) ->rule(UserConstants::ENGLISH_ADDRESS_REGEX), TextInput::make('fa_name_en') ->label("Father's name") ->required() ->minLength(2) ->maxLength(64) ->rule(UserConstants::ENGLISH_ADDRESS_REGEX), TextInput::make('na_number') ->translateLabel() ->maxLength(255), Select::make('gender') ->translateLabel() ->required() ->options(GenderEnum::class), DatePicker::make('bdate') ->translateLabel() ->rule('date') ->maxDate(now()) ->minDate('1900-01-01') ->afterStateHydrated(function ($record, $get) { $date = $get('bdate'); if (!checkdate(intval(substr($date, 5, 2)), intval(substr($date, 8, 2)), intval(substr($date, 0, 4)))) { $this->addError('date_field', __('Invalid date format')); } }) ->required(), Select::make('country') ->translateLabel() ->required() ->live() ->options(function () { if (app()->getLocale() == 'ar') { $countries = Country::pluck('country', 'co_id'); } else { $countries = Country::pluck('country_e', 'co_id'); } return $countries; }) ->afterStateHydrated(function ($record, Get $get, Set $set) { if (app()->getLocale() == 'ar') { $cities = City::where('ci_id', $record?->city)->value('co_id'); } else { $cities = City::where('ci_id', $record?->citye)->value('co_id'); } $set('country', $cities); }) , Select::make('city') ->translateLabel() ->required() ->options( function (Get $get, Set $set) { if (app()->getLocale() == 'ar') { $cities = City::where('co_id', $get('country'))->pluck('city', 'ci_id'); } else { $cities = City::where('co_id', $get('country'))->pluck('citye', 'ci_id'); } return $cities; } ) ->disabled(fn(Get $get): bool => !filled($get('country'))), ]) ->columns(2), Section::make(__('Contact information'))->schema([ TextInput::make('email') ->translateLabel() ->email() ->required() ->maxLength(320) ->unique(ignoreRecord: true), TextInput::make('semail') ->translateLabel() ->email() ->maxLength(320) ->different('email') ->unique(ignoreRecord: true), PhoneInput::make('phone') ->translateLabel() ->rule('phone') ->unique('users', 'phone', ignoreRecord: true), PhoneInput::make('fax') ->translateLabel() ->rule('phone'), PhoneInput::make('mobile') ->translateLabel() ->required() ->rule('phone'), TextInput::make('en_address') ->translateLabel() ->maxLength(255) ->rule(UserConstants::ENGLISH_ADDRESS_REGEX), TextInput::make('ar_address') ->translateLabel() ->maxLength(255) ->rule(UserConstants::ARABIC_ADDRESS_REGEX), ]) ->columns(2), Section::make()->schema([ Toggle::make('show_contact')->label(__('show_contact')), ]) ]) // Select::make('secret_q') // ->translateLabel() // ->options(SecretQuestionEnum::class), // TextInput::make('secret_a') // ->translateLabel() // ->maxLength(255), // ) ->extraAttributes(['id' => 'customForm']) ->statePath('data') ->model(auth()->user()); } public function update() { // dd($this->form->getState()['bdate']); auth()->user()->update( $this->form->getState() ); Notification::make() ->title(__('User data updated')) ->success() ->send(); $this->redirect(route('filament.admin.pages.dashboard')); } protected function getFormActions(): array { return [ Action::make('Update') ->label(__('Update')) ->color('primary') ->submit(__('Update')), ]; } }