PHPackages                             fengbingji/geetest - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. fengbingji/geetest

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fengbingji/geetest
==================

Geetest Package for Laravel8

v3.1.0(5y ago)015MITPHPPHP ^7.3

Since Jul 25Pushed 5y agoCompare

[ Source](https://github.com/fengbingji/LaravelGeetest)[ Packagist](https://packagist.org/packages/fengbingji/geetest)[ RSS](/packages/fengbingji-geetest/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (21)Used By (0)

Laravel Geetest
===============

[](#laravel-geetest)

[![Build Status](https://camo.githubusercontent.com/cd7cd928db504ef1190c885d5e95148ab54f9e12933bb0c922cb04cb2e555943/68747470733a2f2f7472617669732d63692e6f72672f4765726d65792f4c61726176656c476565746573742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Germey/LaravelGeetest)[![DUB](https://camo.githubusercontent.com/8121ceb3fbe8002c3601863db4562fc93003a0c3b61bed6439bc189d0fd7dc98/68747470733a2f2f696d672e736869656c64732e696f2f6475622f6c2f766962652d642e7376673f6d61784167653d323539323030303f7374796c653d706c6173746963)](https://github.com/Germey/LaravelGeetest)[![Support](https://camo.githubusercontent.com/a92dc00aa4ee57a96009ec5b181eae7b814bd4864bf6d54dd1b48f48de2d48a1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f737570706f72742d6c61726176656c2d6f72616e67652e737667)](https://laravel.com/)[![Release](https://camo.githubusercontent.com/747531579af19d7c041d793fa408cb5069cc193d47d66ec88d610b3159f39146/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656c656173652d332e302e302d6f72616e67652e737667)](https://github.com/Germey/LaravelGeetest/releases)

Laravel Geetest is a package for Laravel 5-8 developed by [Germey](http://cuiqingcai.com). It provides simple usage for laravel of [Geetest](http://www.geetest.com/).

Geetest Demo: [Geetest](https://www.geetest.com/show)

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

[](#installation)

Laravel 5.0 or later is required.

This Package now supports Geetest 3.0.

For Geetest 2.0, please see [LaravelGeetest 2.0](https://github.com/Germey/LaravelGeetest/tree/v2.0.3)

To get the latest version of Laravel Geetest, simply require the project using Composer:

```
$ composer require fengbingji/geetest

```

Or you can add following to `require` key in `composer.json`:

```
"fengbingji/geetest": "~3.0"
```

then run:

```
$ composer update

```

Next, You should need to register the service provider. Open up `config/app.php` and add following into the `providers` key:

```
Germey\Geetest\GeetestServiceProvider::class
```

And you can register the Geetest Facade in the `aliases` of `config/app.php` :

```
'Geetest' => Germey\Geetest\Geetest::class
```

Configuration
-------------

[](#configuration)

To get started, you need to publish vendor assets using the following command:

```
$ php artisan vendor:publish --tag=geetest

```

This will create a config file named `config/geetest.php` which you can configure geetest as you like.

It will also generate a views folder named `resources/views/vendor/geetest`, there will be a view file named `geetest.blade.php`. Here you can configure styles of geetest. For example, you can change the script `alert()` as you like.

Usage
-----

[](#usage)

Firstly, You need to register in [Geetest](http://www.geetest.com/). Creating an app and get `ID` and `KEY`.

For example. You can see app `ID` and `KEY` after you added an app in [Geetest Admin Page](http://account.geetest.com)

[![](https://camo.githubusercontent.com/37f26aa21583b1a261eff9193a26247229c5d73f1cb2e3847d02b1780c1d3ecf/68747470733a2f2f7773332e73696e61696d672e636e2f6c617267652f303036744b6654636c7931666833716865727739316a33316b773065367134702e6a7067)](https://camo.githubusercontent.com/37f26aa21583b1a261eff9193a26247229c5d73f1cb2e3847d02b1780c1d3ecf/68747470733a2f2f7773332e73696e61696d672e636e2f6c617267652f303036744b6654636c7931666833716865727739316a33316b773065367134702e6a7067)

Then configure them in your `.env` file because you'd better not make them public.

Add them to `.env` as follows:

```
GEETEST_ID=0f1097bef7xxxxxx9afdeced970c63e4
GEETEST_KEY=c070f0628xxxxxxe68e138b55c56fb3b

```

Then, You can use `render()` in views like following, It will render a geetest code captcha:

```
{!! Geetest::render() !!}
```

For example, you can use it in `form` like this:

```

    {!! Geetest::render() !!}

```

It will render like this:

[![](https://camo.githubusercontent.com/133b744299921cdd42226d3171b51f1bafccd38706eadd4c97f9ccbb068dfec2/68747470733a2f2f7773342e73696e61696d672e636e2f6c617267652f303036744b6654636c7931666833717033666861666a333069383035327133372e6a7067)](https://camo.githubusercontent.com/133b744299921cdd42226d3171b51f1bafccd38706eadd4c97f9ccbb068dfec2/68747470733a2f2f7773342e73696e61696d672e636e2f6c617267652f303036744b6654636c7931666833717033666861666a333069383035327133372e6a7067)

When you click the `submit` button, it will verify the Geetest Code. If you didn't complete the validation, it will alert some text and prevent the form from submitting.

Or you can set other style of Geetest:

```
{!! Geetest::render('float') !!}
{!! Geetest::render('bind') !!}
{!! Geetest::render('popup') !!}
{!! Geetest::render('custom') !!}
```

Then it will be embed or popup style in the website. Default to `float`.

If the validation is completed, the form will be submitted successfully.

Server Validation
-----------------

[](#server-validation)

What's the reason that Geetest is safe? If it only has client validation of frontend, can we say it is complete? It also has server validation to ensure that the post request is validate.

First I have to say that you can only use Geetest of Frontend. But you can also do simple things to achieve server validation.

You can use `$this->validate()` method to achieve server validation. Here is an example:

```
use Illuminate\Http\Request;

class BaseController extends Controller
{
    /**
     * @param Request $request
     */
    public function postValidate(Request $request)
    {
        $this->validate($request, [
            'geetest_challenge' => 'geetest',
        ], [
            'geetest' => config('geetest.server_fail_alert')
        ]);
        return true;
    }
}
```

If we use Geetest, the form will post three extra parameters `geetest_challenge` `geetest_validate` `geetest_seccode`. Geetest use these three parameters to achieve server validation.

If you use ORM, we don't need to add these keys to Model, so you should add following in Model:

```
protected $guarded = ['geetest_challenge', 'geetest_validate', 'geetest_seccode'];
```

You can define alert text by altering `server_fail_alert` in `config/geetest.php`

Also you can use Request to achieve validation:

```
