Skip to content

laravel-mosparo - spam protection for Laravel and Livewire, without the captcha

Latest versionTotal downloadsTestsDocumentationPHP versionLaravel versionLicense

Laravel × mosparo ​

Documentation: exeque.github.io/laravel-mosparo

mosparo spam protection for Laravel and Livewire. Put the box in a form with one directive, and check the submission with a validation rule, a Livewire trait or a facade, naming the fields mosparo must have checked.

Install ​

bash
composer require exeque/laravel-mosparo
dotenv
MOSPARO_HOST=https://mosparo.example.com
MOSPARO_UUID=your-project-uuid
MOSPARO_PUBLIC_KEY=your-public-key
MOSPARO_PRIVATE_KEY=your-private-key

Use ​

blade
<head>
    @mosparoScript
</head>

<form method="post" action="/newsletter">
    @csrf
    <input name="email" type="email">

    @mosparo
    @mosparoError <p class="error">{{ $message }}</p> @enderror

    <button type="submit">Subscribe</button>
</form>

A plain form post is checked by a validation rule:

php
use ExeQue\Mosparo\Rules\ValidMosparo;

'_mosparo_submitToken' => [new ValidMosparo(['email'])],

A Livewire component uses the trait:

php
use ExeQue\Mosparo\Livewire\Concerns\InteractsWithMosparo;
use Livewire\Component;

class SignIn extends Component
{
    use InteractsWithMosparo;

    public SignInForm $form;

    public function signIn(): void
    {
        if (! $this->mosparo->verify($this->form, ['email'])) {
            return;
        }

        // ...
    }
}

Anything else asks the facade:

php
use ExeQue\Mosparo\Facades\Mosparo;

Mosparo::passes($formData, $submitToken, $validationToken, ['email', 'message']);

Features ​

Read on in the documentation.

License ​

The code is MIT; see LICENSE.md.

The cover shows Mo, the sparrow, by mosparo, licensed under CC BY-SA 4.0. The cover and the other artwork in art/ are CC BY-SA 4.0 as well; see art/LICENSE.md. mosparo and Laravel do not endorse this package.