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

src/Form/Field/Currency.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
class Currency extends Text
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $symbol = '$';
11
12
    /**
13
     * @var array
14
     */
15
    protected static $js = [
16
        '/vendor/laravel-admin/AdminLTE/plugins/input-mask/jquery.inputmask.bundle.min.js',
17
    ];
18
19
    /**
20
     * @see https://github.com/RobinHerbots/Inputmask#options
21
     *
22
     * @var array
23
     */
24
    protected $options = [
25
        'alias'              => 'currency',
26
        'radixPoint'         => '.',
27
        'prefix'             => '',
28
        'removeMaskOnSubmit' => true,
29
    ];
30
31
    /**
32
     * Set symbol for currency field.
33
     *
34
     * @param string $symbol
35
     *
36
     * @return $this
37
     */
38
    public function symbol($symbol)
39
    {
40
        $this->symbol = $symbol;
41
42
        return $this;
43
    }
44
45
    /**
46
     * Set digits for input number.
47
     *
48
     * @param int $digits
49
     *
50
     * @return $this
51
     */
52
    public function digits($digits)
53
    {
54
        return $this->options(compact('digits'));
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function prepare($value)
61
    {
62
        return (float) $value;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function render()
69
    {
70
        $this->inputmask($this->options);
71
72
        $this->prepend($this->symbol)
73
            ->defaultAttribute('style', 'width: 120px');
74
75
        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 75 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
76
    }
77
}
78