generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
456 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
blank_issues_enabled: false | ||
contact_links: | ||
- name: Ask a question | ||
url: https://github.com/:vendor_name/:package_name/discussions/new?category=q-a | ||
url: https://github.com/leandrocfe/filament-ptbr-form-fields/discussions/new?category=q-a | ||
about: Ask the community for help | ||
- name: Request a feature | ||
url: https://github.com/:vendor_name/:package_name/discussions/new?category=ideas | ||
url: https://github.com/leandrocfe/filament-ptbr-form-fields/discussions/new?category=ideas | ||
about: Share ideas for new features | ||
- name: Report a security issue | ||
url: https://github.com/:vendor_name/:package_name/security/policy | ||
url: https://github.com/leandrocfe/filament-ptbr-form-fields/security/policy | ||
about: Learn how to notify us for sensitive bugs |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Changelog | ||
|
||
All notable changes to `:package_name` will be documented in this file. | ||
All notable changes to `filament-ptbr-form-fields` will be documented in this file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,167 @@ | ||
# :package_description | ||
# Brazilian pt-BR form fields. | ||
|
||
[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug) | ||
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain) | ||
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug) | ||
<!--delete--> | ||
--- | ||
This repo can be used to scaffold a Laravel package. Follow these steps to get started: | ||
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). | ||
|
||
1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton. | ||
2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files. | ||
3. Have fun creating your package. | ||
4. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course. | ||
--- | ||
<!--/delete--> | ||
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. | ||
This package uses [LaravelLegends/pt-br-validator](https://github.com/LaravelLegends/pt-br-validator) to validate Brazilian Portuguese fields. | ||
|
||
## Support us | ||
![image demo](https://raw.githubusercontent.com/leandrocfe/filament-ptbr-form-fields/develop/screenshots/v1-example.png) | ||
|
||
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/:package_name.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/:package_name) | ||
## Installation | ||
|
||
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). | ||
You can install the package via Composer: | ||
|
||
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). | ||
```bash | ||
composer require leandrocfe/filament-ptbr-form-fields | ||
``` | ||
|
||
## Installation | ||
## Usage | ||
|
||
You can install the package via composer: | ||
### CPF / CNPJ | ||
|
||
```bash | ||
composer require :vendor_slug/:package_slug | ||
To create a dynamic input that accepts either CPF or CNPJ, use: | ||
|
||
```php | ||
use Leandrocfe\FilamentPtbrFormFields\PtbrCpfCnpj; | ||
PtbrCpfCnpj::make('cpf_or_cnpj') | ||
``` | ||
|
||
You can publish and run the migrations with: | ||
You can also add validation to this field by chaining the rule() method: | ||
|
||
```bash | ||
php artisan vendor:publish --tag=":package_slug-migrations" | ||
php artisan migrate | ||
```php | ||
PtbrCpfCnpj::make('cpf_or_cnpj') | ||
->rule('cpf_ou_cnpj') | ||
``` | ||
|
||
You can publish the config file with: | ||
If you want to create an input that only accepts CPF or only accepts CNPJ, use: | ||
|
||
```bash | ||
php artisan vendor:publish --tag=":package_slug-config" | ||
```php | ||
//CPF | ||
PtbrCpfCnpj::make('cpf') | ||
->cpf() | ||
``` | ||
|
||
```php | ||
//CNPJ | ||
PtbrCpfCnpj::make('cnpj') | ||
->cnpj() | ||
``` | ||
|
||
This is the contents of the published config file: | ||
You can also add validation to these fields as well: | ||
|
||
```php | ||
return [ | ||
]; | ||
//CPF with validation | ||
PtbrCpfCnpj::make('cpf') | ||
->cpf() | ||
->rule('cpf') | ||
``` | ||
|
||
Optionally, you can publish the views using | ||
```php | ||
//CNPJ with validation | ||
PtbrCpfCnpj::make('cnpj') | ||
->cnpj() | ||
->rule('cnpj') | ||
``` | ||
|
||
```bash | ||
php artisan vendor:publish --tag=":package_slug-views" | ||
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: | ||
|
||
```php | ||
PtbrCpfCnpj::make('cpf') | ||
->cpf('999999999-99') | ||
``` | ||
|
||
## Usage | ||
```php | ||
PtbrCpfCnpj::make('cnpj') | ||
->cnpj('99999999/9999-57') | ||
``` | ||
|
||
### Phone number | ||
|
||
To create a dynamic input that formats phone numbers with DDD, use: | ||
|
||
```php | ||
$variable = new VendorName\Skeleton(); | ||
echo $variable->echoPhrase('Hello, VendorName!'); | ||
use Leandrocfe\FilamentPtbrFormFields\PtbrPhone; | ||
PtbrPhone::make('phone_number') | ||
``` | ||
|
||
If you want to use a custom phone number format, use the format() method with a string argument representing the desired format: | ||
|
||
```php | ||
PtbrPhone::make('phone_number') | ||
->format('99999-9999') | ||
``` | ||
|
||
```php | ||
PtbrPhone::make('phone_number') | ||
->format('(+99)(99)99999-9999') | ||
``` | ||
|
||
### Money | ||
|
||
To create a money input with the Brazilian currency symbol as the prefix, use: | ||
|
||
```php | ||
use Leandrocfe\FilamentPtbrFormFields\PtbrMoney; | ||
PtbrMoney::make('price') | ||
``` | ||
|
||
If you want to remove the prefix, use the prefix() method with a null argument: | ||
|
||
```php | ||
PtbrMoney::make('price') | ||
->prefix(null) | ||
``` | ||
|
||
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: | ||
|
||
```php | ||
PtbrMoney::make('price') | ||
->dehydrateMask(false) | ||
``` | ||
|
||
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: | ||
|
||
```php | ||
PtbrMoney::make('price') | ||
->initialValue(null) | ||
``` | ||
|
||
### Address | ||
|
||
To integrate with the ViaCep API for CEP validation and address autofill, use: | ||
|
||
```php | ||
use Leandrocfe\FilamentPtbrFormFields\PtbrCep; | ||
use Filament\Forms\Components\TextInput; | ||
PtbrCep::make('postal_code') | ||
->viaCep( | ||
mode: 'suffix', // Determines whether the action should be appended to (suffix) or prepended to (prefix) the cep field, or not included at all (none). | ||
errorMessage: 'CEP inválido.', // Error message to display if the CEP is invalid. | ||
|
||
/** | ||
* Other form fields that can be filled by ViaCep. | ||
* The key is the name of the Filament input, and the value is the ViaCep attribute that corresponds to it. | ||
* More information: https://viacep.com.br/ | ||
*/ | ||
setFields: [ | ||
'street' => 'logradouro', | ||
'number' => 'numero', | ||
'complement' => 'complemento', | ||
'district' => 'bairro', | ||
'city' => 'localidade', | ||
'state' => 'uf' | ||
] | ||
), | ||
|
||
TextInput::make('street'), | ||
TextInput::make('number'), | ||
TextInput::make('complement'), | ||
TextInput::make('district'), | ||
TextInput::make('city'), | ||
TextInput::make('state'), | ||
``` | ||
|
||
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. | ||
|
||
## Testing | ||
|
||
```bash | ||
|
@@ -81,12 +178,12 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details. | |
|
||
## Security Vulnerabilities | ||
|
||
Please review [our security policy](../../security/policy) on how to report security vulnerabilities. | ||
If you discover a security vulnerability within this package, please send an e-mail to <[email protected]>. | ||
|
||
## Credits | ||
|
||
- [:author_name](https://github.com/:author_username) | ||
- [All Contributors](../../contributors) | ||
- [Leandro Costa Ferreira](https://github.com/leandrocfe) | ||
- [All Contributors](../../contributors) | ||
|
||
## License | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
return []; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.