F
Filament5w ago
br1

Compound key validation at Form's DatePicker

Given this migration: Schema::table('incomes', function (Blueprint $table): void { $table->date('emission_date') ->nullable(false) ->change(); $table->unique(['user_id', 'emission_date'], 'user_emission_date_unique'); }); Where emission_date is always normalized to: $income->emission_date = Carbon::parse($income->emission_date)->startOfMonth(); Before create, I have to check that it doesn't exists any register with that compound key (user_emission_date_unique) at the following form of a Resource: public static function form(Form $form): Form { Log::info('form: ' . PanelUrlHelper::getUserIdFromUrl()); return $form ->schema([ TextInput::make('user_id') ->label('ID de usuario') ->default(PanelUrlHelper::getUserIdFromUrl()) ->readOnly(), TextInput::make('amount') ->label('Monto') ->numeric() ->inputMode('decimal'), DatePicker::make('emission_date') ->label('Fecha de Emisión') ->native(false) ->displayFormat('d/m/Y') ->closeOnDateSelection() ->seconds(false) ->required() ->unique() , ]); } I tried different ways, even with custom rules, but I can't get it. As can you see I've logged the user_id extracted from url and I obtained that the form it's getting rendered twice, once with the id and other with the id = 0: [2025-03-13 12:50:54] testing.INFO: form: 530759726002900 [2025-03-13 12:50:59] testing.INFO: form: 0
2 Replies
br1
br1OP5w ago
Maybe the problem it's because of reactivity? I know that I can use RelationManagers (and I've already did it with them) but my boss want that the user_id remains at the url to mantain the context while the admin browse through the dashboard. In case that I couldn't do this validation with this first approach (using the Resource), Is there a way where I can persist the user_id at the url using the RelationManager?
No description
No description
br1
br1OP5w ago
this is the old solution with RelationManager:
No description

Did you find this page helpful?