Captcha.php 871 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Dcat\Admin\Form\Field;
  3. use Dcat\Admin\Exception\AdminException;
  4. class Captcha extends Text
  5. {
  6. protected $rules = ['required', 'captcha'];
  7. protected $view = 'admin::form.captcha';
  8. public function __construct()
  9. {
  10. if (! class_exists(\Mews\Captcha\Captcha::class)) {
  11. throw new AdminException('To use captcha field, please install [mews/captcha] first.');
  12. }
  13. $this->column = '__captcha__';
  14. $this->label = trans('admin.captcha');
  15. }
  16. public function setForm($form = null)
  17. {
  18. parent::setForm($form);
  19. if (method_exists($this->form, 'ignore')) {
  20. $this->form->ignore($this->column);
  21. }
  22. return $this;
  23. }
  24. public function render()
  25. {
  26. $this->addVariables(['captchaSrc' => captcha_src()]);
  27. return parent::render();
  28. }
  29. }