devaslanphp / project-management

An open source Project management tool based on Laravel and Filament
https://devaslanphp.github.io/project-management
MIT License
682 stars 188 forks source link

fix / ProjectResource: can't save unique ticket_prefix #74

Closed kamilst96 closed 1 year ago

kamilst96 commented 1 year ago

Related issue: #63 Regression introduced by fix: #73

When editing a Project, it cannot be saved, because validator doesn't exclude current model's value from the check. It can be fixed using ignoreRecord: true

Forms\Components\TextInput::make('ticket_prefix')
  ...
  ->unique(ignoreRecord: true)

Documentation: https://filamentphp.com/docs/2.x/forms/validation#unique

Filament Admin resolves the table and column based on resource model and field name, so manually inputting it is not necessary, unless the source of uniqueness really is somewhere else, so I removed it.

If you prefer verbosity, it can be reintroduced like this:

Forms\Components\TextInput::make('ticket_prefix')
  ...
  ->unique(table: Project::class, column: 'ticket_prefix', ignoreRecord: true)