Completed
Push — master ( 82be35...1537c0 )
by Song
02:28
created

src/Form/Field/Captcha.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
use Encore\Admin\Form;
6
7
class Captcha extends Text
8
{
9
    protected $rules = 'required|captcha';
10
11
    protected $view = 'admin::form.captcha';
12
13
    public function __construct($column, $arguments = [])
14
    {
15
        if (!class_exists(\Mews\Captcha\Captcha::class)) {
16
            throw new \Exception('To use captcha field, please install [mews/captcha] first.');
17
        }
18
19
        $this->column = '__captcha__';
20
        $this->label = trans('admin.captcha');
21
    }
22
23
    public function setForm(Form $form = null)
24
    {
25
        $this->form = $form;
26
27
        $this->form->ignore($this->column);
28
29
        return $this;
30
    }
31
32
    public function render()
33
    {
34
        $this->script = <<<EOT
35
36
$('#{$this->column}-captcha').click(function () {
37
    $(this).attr('src', $(this).attr('src')+'?'+Math.random());
38
});
39
40
EOT;
41
42
        return parent::render();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::render(); of type string|Illuminate\View\V...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 42 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
43
    }
44
}
45