F
Filament12mo ago
inluxc

Rules in TextInput breaks server.

When i add the following rule to an TextInput and i try to save the form is breaks the server and i need to restart it.
Forms\Components\TextInput::make('slug')
->hint('Translatable')
->hintColor('primary')
->hintIcon('heroicon-m-language')
->disabled()
->rules([
function () {
return function ($value, Closure $fail, $livewire) {
// Check if slug belongs to currrent page
$count = Sitemap::all()
->where('slug', '=', $value)
->where('resource_id', $livewire->record->getAttribute('id'))
->where('resource_type', 'page')
->count();
if ($count > 0) {
return;
}

// Check if slug already exists in another resource
$countExists = Sitemap::all()
->where('slug', '=', $value)
->count();
if ($countExists > 0) {
$fail("The slug already exists in another resource");
}
};
},
])
->maxLength(255),
Forms\Components\TextInput::make('slug')
->hint('Translatable')
->hintColor('primary')
->hintIcon('heroicon-m-language')
->disabled()
->rules([
function () {
return function ($value, Closure $fail, $livewire) {
// Check if slug belongs to currrent page
$count = Sitemap::all()
->where('slug', '=', $value)
->where('resource_id', $livewire->record->getAttribute('id'))
->where('resource_type', 'page')
->count();
if ($count > 0) {
return;
}

// Check if slug already exists in another resource
$countExists = Sitemap::all()
->where('slug', '=', $value)
->count();
if ($countExists > 0) {
$fail("The slug already exists in another resource");
}
};
},
])
->maxLength(255),
Can someone point me out what I am doing wrong?
2 Replies
awcodes
awcodes12mo ago
How is it “breaking the server”?
inluxc
inluxcOP12mo ago
Good question, the server just stops responding and i have to restart it.. No logs are registed I fixed creating a Rule class,
Want results from more Discord servers?
Add your server