F
Filament6mo 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
awcodes6mo ago
How is it “breaking the server”?
inluxc
inluxc6mo 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
More Posts
Problem with opt out tenancyIn my Application, I am using multi tenancy. I have one resource, that doesnt have tenancy. ThereforProblem using Many to Many relationship, using filament v2.``` SQLSTATE[HY000]: General error: 1364 Field 'category_id' doesn't have a default value INSERT INTPass the value of navigationLabel to create pageSo, I have a Students table and it has a field called gametype, which is basically hidden from the uBest practice to inject additional attributes into my Laravel model to persist in stateHello, I have an Application model (paper form converted to digital) where I retreive extra attributOpen modal showing the edit view of a different resourceI have two different resources 'Verification' and 'Bookings'. Both resources are tied to the BookingDependent select in attach actionI would like to make dependent select in my attach action. It would depend on the $action->getRecordIs there a way to get the current tenant in isTenantSubscriptionRequired()?For a Resource in the Panel, I need to get the current tenant and when implementing `isTenantSubscriPlaceholder for empty Select relationshipHi, I can't find a way to have a placeholder text in case there is no result for my relationship SelHow To Disable a Table Column Reactively After Toggle Column ActionHi, I have a relation manager page where i list some records with two toggle columns of is_accepted Attach formI have model of user function, user and event. I have table for user functions, users, events and pi