Select field with relationship, does it need validation?

Forms\Components\Select::make('profile_branch_id')
->relationship('branch', 'branch_number', function (Builder $query) {
$query->where('profile_id', $this->ownerRecord->getKey());
})
->exists('profile_branches', 'id', function (Exists $rule) {
$rule->where('profile_id', $this->ownerRecord->getKey());
}),
Forms\Components\Select::make('profile_branch_id')
->relationship('branch', 'branch_number', function (Builder $query) {
$query->where('profile_id', $this->ownerRecord->getKey());
})
->exists('profile_branches', 'id', function (Exists $rule) {
$rule->where('profile_id', $this->ownerRecord->getKey());
}),
When creating a select field with relationship options do i need to validate that the selected option is actually in the list of available options or does the component check this already?
Solution:
I think not vendor/filament/forms/src/Components/Select.php:930 ```php...
Jump to solution
3 Replies
Solution
Lara Zeus
Lara Zeus10mo ago
I think not vendor/filament/forms/src/Components/Select.php:930 `php return Rule::exists( $relationship->getModel()::class, $component->getQualifiedRelatedKeyNameForRelationship($relationship), );
BlackShadow
BlackShadowOP10mo ago
Nice Thanks!
BlackShadow
BlackShadowOP10mo ago
I forgot to mention that in my case i have to check if the branch belongs to a profile, so i do have to keep the check.
Want results from more Discord servers?
Add your server