Prohibits validation rule

I have a form with two fields - only one should be filled, not both. This would use Laravel’s prohibits (https://laravel.com/docs/10.x/validation#rule-prohibits) normally but that is not supported.

I found an old post on here saying to do this:
->prohibited(fn (Closure $get): bool => filled($get('field1')))

But when I try this I get the following error:

App\Filament\Pages\Tenancy\RegisterCompany::App\Filament\Pages\Tenancy\{closure}(): Argument #1 ($get) must be of type Closure, Filament\Forms\Get given, called in /app/vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35

Here’s my form - either the select should be selected or the input filled, not both:

<?php
namespace App\Filament\Pages\Tenancy;

use App\Models\Company;
use Closure;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Tenancy\RegisterTenant;

class RegisterCompany extends RegisterTenant
{
    public static function getLabel(): string
    {
        return 'Add or join company';
    }

    public function form(Form $form): Form
    {

        $companies = Company::where('email', 'LIKE', '%' . auth()->user()->email_domain)->get();

        $formSchema = [];

        if ($companies) {
            $formSchema[] = Section::make('Join existing company')->
                description('...')->
                schema([
                    Select::make('company_id')->reactive()->options($companies->pluck('name', 'id')->toArray())->prohibited(fn (Closure $get): bool => filled($get('name'))),
                ]);
        }

        $formSchema[] = Section::make('Create new company')->
            description('...')->
            schema([
                TextInput::make('name')->reactive()->prohibited(fn (Closure $get): bool => filled($get('company_id'))),
            ]);

        return $form->schema($formSchema);
     
    }
}
Was this page helpful?