You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://packagist.org/packages/:vendor_slug/:package_slug)
This repo can be used to scaffold a Laravel package. Follow these steps to get started:
3
+
This package provides custom form fields for [Filament](https://filamentphp.com/) (**>=v2.17.28**) that are commonly used in Brazilian web applications, such as CPF/CNPJ validation, phone number formatting, money with currency symbol, and CEP integration with [ViaCep](https://viacep.com.br).
10
4
11
-
1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton.
12
-
2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files.
13
-
3. Have fun creating your package.
14
-
4. If you need help creating a package, consider picking up our <ahref="https://laravelpackage.training">Laravel Package Training</a> video course.
15
-
---
16
-
<!--/delete-->
17
-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
5
+
This package uses [LaravelLegends/pt-br-validator](https://github.com/LaravelLegends/pt-br-validator) to validate Brazilian Portuguese fields.
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
11
+
You can install the package via Composer:
24
12
25
-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
If you want to use a custom mask for the input, use the cpf() or cnpj() method with a string argument representing the desired mask:
66
+
67
+
```php
68
+
PtbrCpfCnpj::make('cpf')
69
+
->cpf('999999999-99')
59
70
```
60
71
61
-
## Usage
72
+
```php
73
+
PtbrCpfCnpj::make('cnpj')
74
+
->cnpj('99999999/9999-57')
75
+
```
76
+
77
+
### Phone number
78
+
79
+
To create a dynamic input that formats phone numbers with DDD, use:
62
80
63
81
```php
64
-
$variable = new VendorName\Skeleton();
65
-
echo $variable->echoPhrase('Hello, VendorName!');
82
+
use Leandrocfe\FilamentPtbrFormFields\PtbrPhone;
83
+
PtbrPhone::make('phone_number')
66
84
```
67
85
86
+
If you want to use a custom phone number format, use the format() method with a string argument representing the desired format:
87
+
88
+
```php
89
+
PtbrPhone::make('phone_number')
90
+
->format('99999-9999')
91
+
```
92
+
93
+
```php
94
+
PtbrPhone::make('phone_number')
95
+
->format('(+99)(99)99999-9999')
96
+
```
97
+
98
+
### Money
99
+
100
+
To create a money input with the Brazilian currency symbol as the prefix, use:
101
+
102
+
```php
103
+
use Leandrocfe\FilamentPtbrFormFields\PtbrMoney;
104
+
PtbrMoney::make('price')
105
+
```
106
+
107
+
If you want to remove the prefix, use the prefix() method with a null argument:
108
+
109
+
```php
110
+
PtbrMoney::make('price')
111
+
->prefix(null)
112
+
```
113
+
114
+
By default, the mask is removed from the input when it is submitted. If you want to keep the mask, use the dehydrateMask() method with a false argument:
115
+
116
+
```php
117
+
PtbrMoney::make('price')
118
+
->dehydrateMask(false)
119
+
```
120
+
121
+
The initial value of the input is '0,00'. If you want to change the initial value, use the initialValue() method with a string argument:
122
+
123
+
```php
124
+
PtbrMoney::make('price')
125
+
->initialValue(null)
126
+
```
127
+
128
+
### Address
129
+
130
+
To integrate with the ViaCep API for CEP validation and address autofill, use:
131
+
132
+
```php
133
+
use Leandrocfe\FilamentPtbrFormFields\PtbrCep;
134
+
use Filament\Forms\Components\TextInput;
135
+
PtbrCep::make('postal_code')
136
+
->viaCep(
137
+
mode: 'suffix', // Determines whether the action should be appended to (suffix) or prepended to (prefix) the cep field, or not included at all (none).
138
+
errorMessage: 'CEP inválido.', // Error message to display if the CEP is invalid.
139
+
140
+
/**
141
+
* Other form fields that can be filled by ViaCep.
142
+
* The key is the name of the Filament input, and the value is the ViaCep attribute that corresponds to it.
143
+
* More information: https://viacep.com.br/
144
+
*/
145
+
setFields: [
146
+
'street' => 'logradouro',
147
+
'number' => 'numero',
148
+
'complement' => 'complemento',
149
+
'district' => 'bairro',
150
+
'city' => 'localidade',
151
+
'state' => 'uf'
152
+
]
153
+
),
154
+
155
+
TextInput::make('street'),
156
+
TextInput::make('number'),
157
+
TextInput::make('complement'),
158
+
TextInput::make('district'),
159
+
TextInput::make('city'),
160
+
TextInput::make('state'),
161
+
```
162
+
163
+
The mode parameter specifies whether the search action should be appended to or prepended to the CEP field, using the values suffix or prefix. Alternatively, you can use the none value with the ->lazy() method to indicate that the other address fields will be automatically filled only when the CEP field loses focus.
164
+
68
165
## Testing
69
166
70
167
```bash
@@ -81,12 +178,12 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
81
178
82
179
## Security Vulnerabilities
83
180
84
-
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
181
+
If you discover a security vulnerability within this package, please send an e-mail to <leandrocfe@gmail.com>.
0 commit comments