Share validation rules with api resource controllers

What's the best way to reuse validation rules between my api resource controller and Filament? I've tried to re-use the validation rules from custom FormRequest:

public static function form(Form $form): Form
{
    if($form->getOperation() === 'create') {
        $userRequest = new StoreUserRequest();
    } else {
        $userRequest = new UpdateUserRequest();
    }

    return $form
        ->schema([
            Forms\Components\TextInput::make('first_name')
                ->rules($userRequest->rules()['first_name']),
            Forms\Components\TextInput::make('last_name')
                ->rules($userRequest->rules()['last_name']),
            Forms\Components\TextInput::make('email')
                ->rules($userRequest->rules()['email']),
            Forms\Components\TextInput::make('password')
                ->rules($userRequest->rules()['email'])
                ->dehydrateStateUsing(fn ($state) => Hash::make($state))
                ->dehydrated(fn ($state) => filled($state))
        ]);
}


But I can't seem to get access to the request values. I both the $this->input() and $this->request->all() are completely empty, so my custom validation rules fail.
Was this page helpful?