## 注冊驗證碼
### 安裝擴展包
我們將以第三方擴展包 [mews/captcha](https://github.com/mewebstudio/captcha) 作為基礎來實現 Laravel 中的驗證碼功能。
使用 Composer 安裝:
```php
$ composer require "mews/captcha:~2.0"
```
運行以下命令生成配置文件 `config/captcha.php`:
```php
$ php artisan vendor:publish --provider='Mews\Captcha\CaptchaServiceProvider'
```
我們可以打開配置文件,查看其內容:
*config/captcha.php*
```php
<?php
return [
'characters' => ['2', '3', '4', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'm', 'n', 'p', 'q', 'r', 't', 'u', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'X', 'Y', 'Z'],
'default' => [
'length' => 9,
'width' => 120,
'height' => 36,
'quality' => 90,
'math' => false,
],
'math' => [
'length' => 9,
'width' => 120,
'height' => 36,
'quality' => 90,
'math' => true,
],
'flat' => [
'length' => 6,
'width' => 160,
'height' => 46,
'quality' => 90,
'lines' => 6,
'bgImage' => false,
'bgColor' => '#ecf2f4',
'fontColors' => ['#2c3e50', '#c0392b', '#16a085', '#c0392b', '#8e44ad', '#303f9f', '#f57c00', '#795548'],
'contrast' => -5,
],
'mini' => [
'length' => 3,
'width' => 60,
'height' => 32,
],
'inverse' => [
'length' => 5,
'width' => 120,
'height' => 36,
'quality' => 90,
'sensitive' => true,
'angle' => 12,
'sharpen' => 10,
'blur' => 2,
'invert' => true,
'contrast' => -5,
]
];
```
可以看到這些配置選項都非常通俗易懂,`characters` 選項是用來顯示給用戶的所有字符串,`default`, `flat`, `mini`, `inverse` 分別是定義的四種驗證碼類型,你可以在此修改對應選項自定義驗證碼的長度、背景顏色、文字顏色等屬性,在此不做過多敘述。