unique email with deleted_at

How can i exclude records, which are marked as deleted from the email validation unique? I also need this function:
TextInput::make('email')
->email()
->required()
->unique(ignoreRecord: true)
->label(__('Email'))
->email(),
TextInput::make('email')
->email()
->required()
->unique(ignoreRecord: true)
->label(__('Email'))
->email(),
and i want to inlcude additional something like this:
->unique(modifyRuleUsing: function (Unique $rule) {
return $rule->whereNot('is_deleted', NULL);
->unique(modifyRuleUsing: function (Unique $rule) {
return $rule->whereNot('is_deleted', NULL);
how would look all together please?
6 Replies
toeknee
toeknee13mo ago
Deleted records should be excluded by default using SoftDeletes if setup correctly they should always be hidden unless explicity shown.
toeknee
toeknee13mo ago
Then you would use a trashed filter in the list where for showing trashed items as per: https://filamentphp.com/docs/2.x/tables/filters
Falk Maria Zeitsprung
Thanks for your answer. I have in the model:
class Applicant extends Model
{
use HasFactory, SoftDeletes, Notifiable;
class Applicant extends Model
{
use HasFactory, SoftDeletes, Notifiable;
and i have
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
so that should work out of the box you say? i will test again. Thanks
toeknee
toeknee13mo ago
So you have told it to remove the global scope so now it will show soft deletes by default For it to work, you need to finish the Filament SoftDeletes integration with the Trashed Filter
toeknee
toeknee13mo ago
Therefore the scope you are using on the above shouldn't included soft deletes You will need to double check. Worst case write a custom rule
Want results from more Discord servers?
Add your server