PHPackages                             vivekco/laravel-math-captcha - 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. vivekco/laravel-math-captcha

ActiveLibrary

vivekco/laravel-math-captcha
============================

Simple single-digit arithmetic captcha for Laravel.

v1.1.0(5mo ago)710MITPHPPHP &gt;=8.0

Since Nov 16Pushed 5mo agoCompare

[ Source](https://github.com/vivekco/laravel-math-captcha)[ Packagist](https://packagist.org/packages/vivekco/laravel-math-captcha)[ RSS](/packages/vivekco-laravel-math-captcha/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Laravel MathCaptcha
===================

[](#laravel-mathcaptcha)

A lightweight, privacy-friendly Laravel package that provides **simple single-digit arithmetic CAPTCHA** for human verification.

> Supports only single-digit operations (1–9) with `+`, `-`, and `×`.

---

Features
--------

[](#features)

- Random single-digit math questions.
- Securely stores answers in server-side session.
- Easy integration with controllers and Blade forms.
- Works without external services or images.
- Compatible with Laravel 10+ / 11+.

---

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

[](#installation)

For **local development or testing**, add the package as a path repository in your Laravel app:

```
"repositories": [
    {
        "type": "path",
        "url": "../packages/laravel-math-captcha"
    }
]
```

Require the package:

```
composer require vivekco/laravel-math-captcha:@dev
```

> Laravel 10+ auto-discovers the service provider.
> Optional: publish config if you want to customize defaults:

```
php artisan vendor:publish --provider="Vivekco\MathCaptcha\MathCaptchaServiceProvider" --tag=config
```

---

Usage
-----

[](#usage)

### 1. Generate a Math Question in Controller

[](#1-generate-a-math-question-in-controller)

```
$question = app('mathcaptcha')->generate();
```

- `$question` is a string like `2 + 3`, `4 × 7`, etc.
- The answer is automatically stored in session (`math_captcha_answer` by default).

---

### 2. Blade Form Example (With Error handling)

[](#2-blade-form-example-with-error-handling)

```

    @csrf

    Solve: {{ $question }}

    Submit

 @error('captcha_answer')
        {{ $message }}
@enderror
```

---

### 3. Validation in Controller

[](#3-validation-in-controller)

```
$request->validate([
    'captcha_answer' => ['required', function ($attribute, $value, $fail) {
        if (!app('mathcaptcha')->check($value)) {
            $fail('The math captcha answer is incorrect.');
        }
    }]
]);
```

- `check($value)` returns `true` if correct, `false` if incorrect.

---

Config (Optional)
-----------------

[](#config-optional)

Published config: `config/mathcaptcha.php`

```
return [
    'min' => 1,
    'max' => 9,
    'operations' => ['+', '-', '×'],
    'session_key' => 'math_captcha_answer',
    'allow_negative' => true,
];
```

- `min` / `max`: range of digits.
- `operations`: allowed operators.
- `session_key`: session key storing the answer.
- `allow_negative`: prevent negative results if false.

---

Local Testing
-------------

[](#local-testing)

1. Serve your Laravel app:

```
php artisan serve
```

2. Visit your test route, generate a question, submit correct/incorrect answers.
3. Run package tests (inside package folder):

```
./vendor/bin/phpunit tests
```

---

Contributing
------------

[](#contributing)

- Fork the repository.
- Create a feature branch: `git checkout -b feat/my-feature`.
- Write tests for your changes.
- Commit and push.
- Open a Pull Request describing the change.

Follow **PSR-12 coding standards**.

---

License
-------

[](#license)

MIT © Vivekco

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance70

Regular maintenance activity

Popularity10

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

175d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/589da2afdb3dd0541da1a72513d6d98971cdb47a1f495a3f1eadbf39ad540d01?d=identicon)[vivekco](/maintainers/vivekco)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vivekco-laravel-math-captcha/health.svg)

```
[![Health](https://phpackages.com/badges/vivekco-laravel-math-captcha/health.svg)](https://phpackages.com/packages/vivekco-laravel-math-captcha)
```

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
