https://github.com/creatint/laravel-captcha
Captcha for Laravel5.8+
https://github.com/creatint/laravel-captcha
Last synced: 14 days ago
JSON representation
Captcha for Laravel5.8+
- Host: GitHub
- URL: https://github.com/creatint/laravel-captcha
- Owner: creatint
- Created: 2019-05-06T05:06:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-06T16:25:01.000Z (over 6 years ago)
- Last Synced: 2024-12-19T00:17:53.814Z (about 1 year ago)
- Language: PHP
- Size: 638 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Captcha for Laravel 5
Inspired by [mews/captcha](https://packagist.org/packages/mews/captcha)
## Preview

## Installation
The Captcha Service Provider can be installed via [Composer](http://getcomposer.org) by requiring the
`mews/captcha` package and setting the `minimum-stability` to `dev` (required for Laravel 5) in your
project's `composer.json`.
```json
{
"require": {
"laravel/framework": "5.0.*",
"creatint/captcha": "dev"
},
"minimum-stability": "dev"
}
```
or
Require this package with composer:
```
composer require creatint/captcha
```
Update your packages with ```composer update``` or install with ```composer install```.
In Windows, you'll need to include the GD2 DLL `php_gd2.dll` in php.ini. And you also need include `php_fileinfo.dll` and `php_mbstring.dll` to fit the requirements of `mews/captcha`'s dependencies.
## Usage
To use the Captcha Service Provider, you must register the provider when bootstrapping your Laravel application. There are
essentially two ways to do this.
Find the `providers` key in `config/app.php` and register the Captcha Service Provider.
```php
'providers' => [
// ...
'Creatint\Captcha\CaptchaServiceProvider',
]
```
for Laravel 5.1+
```php
'providers' => [
// ...
Creatint\Captcha\CaptchaServiceProvider::class,
]
```
Find the `aliases` key in `config/app.php`.
```php
'aliases' => [
// ...
'Captcha' => 'Creatint\Captcha\Facades\Captcha',
]
```
for Laravel 5.1+
```php
'aliases' => [
// ...
'Captcha' => Creatint\Captcha\Facades\Captcha::class,
]
```
## Configuration
To use your own settings, publish config.
```$ php artisan vendor:publish```
`config/captcha.php`
```php
return [
'default' => [
'length' => 5,
'width' => 120,
'height' => 36,
'quality' => 90,
'math' => true, //Enable Math Captcha
],
// ...
];
```
## Example Usage
```php
// [your site path]/Http/routes.php
Route::any('captcha-test', function() {
if (request()->getMethod() == 'POST') {
$rules = ['captcha' => 'required|captcha'];
$validator = validator()->make(request()->all(), $rules);
if ($validator->fails()) {
echo '
Incorrect!
';
} else {
echo 'Matched :)
';
}
}
$form = '';
$form .= '';
$form .= '' . captcha_img() . '
';
$form .= '';
$form .= 'Check
';
$form .= '';
return $form;
});
```
# Return Image
```php
captcha();
```
or
```php
Captcha::create();
```
# Return URL
```php
captcha_src();
```
or
```
Captcha::src();
```
# Return HTML
```php
captcha_img();
```
or
```php
Captcha::img();
```
# To use different configurations
```php
captcha_img('flat');
Captcha::img('inverse');
```
etc.
Based on [Intervention Image](https://github.com/Intervention/image)