F
Filamentβ€’14mo ago
Finn

Required but only on create?

Is there a way to set a field to only be required on a create action? For example when editing a user - on create they require a password to be entered but on update they do not always need to update their password.
Solution:
The required method accepts a callback and you can inject the current operation into that callback:
->required(fn (string $operation): bool => $operation === 'create')
->required(fn (string $operation): bool => $operation === 'create')
...
Jump to solution
6 Replies
toeknee
toekneeβ€’14mo ago
->required(fn($context) => $context === 'create')
Solution
ConnorHowell
ConnorHowellβ€’14mo ago
The required method accepts a callback and you can inject the current operation into that callback:
->required(fn (string $operation): bool => $operation === 'create')
->required(fn (string $operation): bool => $operation === 'create')
ConnorHowell
ConnorHowellβ€’14mo ago
Pretty sure it's 'operation' and not 'context'?
toeknee
toekneeβ€’14mo ago
Could be in V3... not fully on it yet
Finn
FinnOPβ€’14mo ago
worked perfectly, thank you. πŸ™‚
awcodes
awcodesβ€’14mo ago
$context still works in v3 for legacy. But $operation is correct.
Want results from more Discord servers?
Add your server