PHPackages                             yepsua/filament-captcha-field - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. yepsua/filament-captcha-field

ActiveLibrary

yepsua/filament-captcha-field
=============================

Provides a captcha field for the Filament Forms

v0.1.1(3y ago)186.8k↓25.6%4[2 PRs](https://github.com/yepsua/filament-captcha-field/pulls)MITPHPPHP ^8.0

Since Sep 15Pushed 2y ago2 watchersCompare

[ Source](https://github.com/yepsua/filament-captcha-field)[ Packagist](https://packagist.org/packages/yepsua/filament-captcha-field)[ Docs](https://github.com/yepsua/filament-captcha-field)[ RSS](/packages/yepsua-filament-captcha-field/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (14)Versions (5)Used By (0)

Provides a captcha field for the Filament Forms
===============================================

[](#provides-a-captcha-field-for-the-filament-forms)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b70f4601d0901777fff1e5b337ed1675fc3f90e8d6bd7dd77d110bac403105f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7965707375612f66696c616d656e742d636170746368612d6669656c642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yepsua/filament-captcha-field)[![GitHub Tests Action Status](https://camo.githubusercontent.com/7aa689657087898c7878ffe86d59a8df06661f8f6febd6df3e0bf694667d0c4d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7965707375612f66696c616d656e742d636170746368612d6669656c642f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/yepsua/filament-captcha-field/actions?query=workflow%3Arun-tests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/be5b3d635c1f1a9dbf4dece4196f057bd86575772f11fa94580a15ebeb5017b7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7965707375612f66696c616d656e742d636170746368612d6669656c642f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/yepsua/filament-captcha-field/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/e205eda9cdf0f6a6b4a6b63c20f1c2f1cb2dc4b0085e1ac5b54a2c364499d38b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7965707375612f66696c616d656e742d636170746368612d6669656c642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yepsua/filament-captcha-field)

Easy integration with [mewebstudio/captcha](https://github.com/mewebstudio/captcha) for the Filament forms.

Requirements:
-------------

[](#requirements)

- PHP extension: ext-gd

Installation
------------

[](#installation)

Install the package via composer:

```
composer require yepsua/filament-captcha-field
```

Publish the package mewebstudio/captcha config file:

```
php artisan vendor:publish --provider="Mews\Captcha\CaptchaServiceProvider" --tag="config"
```

Usage
-----

[](#usage)

You can include the captcha field like any other filament field.

```
    use Yepsua\Filament\Forms\Components\Captcha;
    ...
    protected function getFormSchema(): array
    {
        return [
            Forms\Components\TextInput::make('username'),
            Forms\Components\TextInput::make('password')->type('password'),
            Captcha::make('captcha')
        ];
    }
```

You can also just display the image and validate the captcha using any other TextInput field:

```
    use Yepsua\Filament\Forms\Components\CaptchaImage;
    ...
    protected function getFormSchema(): array
    {
        return [
            Forms\Components\TextInput::make('username'),
            Forms\Components\TextInput::make('password')->type('password'),
            Forms\Components\TextInput::make('captcha')->required()->rules('required|captcha'),
            CaptchaImage::make('captchaImg')
        ];
    }
```

The captcha uses by default the `flat` config. You can create/update the captcha configs in the file: `config/captcha.php`.

You can switch to any other available captcha config, like the `math` config:

```
    use Yepsua\Filament\Forms\Components\Captcha;
    ...
    protected function getFormSchema(): array
    {
        return [
            Captcha::make('captcha')->config('math')
        ];
    }
```

For more info about the captcha configuration, please read the [mewebstudio/captcha](https://github.com/mewebstudio/captcha) documentation.

Translations
------------

[](#translations)

This package and mewebstudio/captcha don't provide any translation for the captcha validation message, but you can translate the message by yourself, just add the item in the file `resources/lang/{lang}/validation.php`

```
return [
    ...
    'captcha'             => 'Invalid captcha.',
    ...
]
```

Case of use: Add a captcha in the filament login form:
------------------------------------------------------

[](#case-of-use-add-a-captcha-in-the-filament-login-form)

1. Extend the Login page class to add the new field into the form:

```
