exeque / laravel-mosparo
mosparo spam protection for Laravel and Livewire: a configured client, a validation rule, a Blade box and a Livewire form that asks for fresh tokens after every check.
Requires
- php: ^8.4
- illuminate/contracts: ^13.0
- illuminate/support: ^13.0
- illuminate/validation: ^13.0
- illuminate/view: ^13.0
- mosparo/php-api-client: ^2.0
Requires (Dev)
- laravel/pint: ^1.21
- livewire/livewire: ^4.0
- orchestra/testbench: ^11.3
- pestphp/pest: ^5.0
Suggests
- livewire/livewire: Required for MosparoForm and the InteractsWithMosparo trait.
Provides
None
Conflicts
None
Replaces
None
README
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
composer require exeque/laravel-mosparo
MOSPARO_HOST=https://mosparo.example.com MOSPARO_UUID=your-project-uuid MOSPARO_PUBLIC_KEY=your-public-key MOSPARO_PRIVATE_KEY=your-private-key
Use
<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:
use ExeQue\Mosparo\Rules\ValidMosparo; '_mosparo_submitToken' => [new ValidMosparo(['email'])],
A Livewire component uses the trait:
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:
use ExeQue\Mosparo\Facades\Mosparo; Mosparo::passes($formData, $submitToken, $validationToken, ['email', 'message']);
Features
- Statistics, rule packages and metadata as read-only data objects, with optional caching
- Several mosparo projects in one application, picked by name
- Disabled with one env key, and faked in your tests
- Visible and invisible boxes, started wherever they appear: Livewire updates,
wire:navigate, the back button - The error message in 29 European languages
- A workbench with a real mosparo, through lerd or Docker
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.
