agenciafmd / admix-addresses
Endereços - Agência F&MD
Installs: 948
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
Language:Blade
Requires
- agenciafmd/admix-form: dev-master
Requires (Dev)
- orchestra/testbench: ^4.0
This package is auto-updated.
Last update: 2024-12-07 19:44:40 UTC
README
- Acopla os campos de endereço / mapa na model
Instalação
composer require agenciafmd/admix-addresses:dev-master
Configuração
Model
Na model Package.php
acrescente a Trait
e o $guarded
use Agenciafmd\Addresses\Traits\AddressTrait;
...
class Package extends Model implements AuditableContract
...
use AddressTrait
...
protected $guarded = [
...'address',...
];
View (TODO: refatorar para o blade component)
Na view que será implementada os endereços, adicione
@include('agenciafmd/addresses::default')
Caso seja necessário a customização, adicione
@include('agenciafmd/addresses::default', ['title' => 'Endereço do Ponto de Venda', 'collection' => 'pos'])
Acrescente tambem os scripts no @push('scripts')
@push('scripts')
@include('agenciafmd/addresses::scripts')
@endpush
Validação
Em Http/Requests/PackageRequest.php
acrescentar
public function rules()
{
return [
...
'address.*.full_street' => [
'required',
'max:150',
],
'address.*.postcode' => [
'required',
'max:150',
],
'address.*.street' => [
'required',
'max:150',
],
'address.*.number' => [
'required',
'max:150',
],
'address.*.complement' => [
'nullable',
'max:150',
],
'address.*.neighborhood' => [
'required',
'max:150',
],
'address.*.city' => [
'required',
'max:150',
],
'address.*.state' => [
'required',
'max:150',
],
'address.*.state_initials' => [
'required',
'max:150',
],
'address.*.latitude' => [
'required',
'max:150',
],
'address.*.longitude' => [
'required',
'max:150',
],
...
];
}
public function attributes()
{
return [
...
'address.*.full_street' => 'endereço completo',
'address.*.postcode' => 'cep',
'address.*.street' => 'endereço',
'address.*.number' => 'número',
'address.*.complement' => 'complemento',
'address.*.neighborhood' => 'bairro',
'address.*.city' => 'cidade',
'address.*.state' => 'estado',
'address.*.state_initials' => 'sigla do estado',
'address.*.latitude' => 'latitude',
'address.*.longitude' => 'longitude',
...
];
}
Factories (TODO: refatorar o how to)
...
$item->addAddress('default', [
'full_street' => $faker->streetAddress,
'postcode' => $faker->postcode,
'street' => $faker->streetName,
'number' => $faker->buildingNumber,
'neighborhood' => $faker->citySuffix,
'complement' => $faker->citySuffix,
'city' => $faker->city,
'state' => $faker->state,
'state_initials' => $faker->stateAbbr,
'latitude' => $faker->latitude($min = -20.8, $max = -20.9),
'longitude' => $faker->longitude($min = -49.4, $max = -50.3),
]);
...
Uso
Quando for necessário, chame os dados
$model->address()->full_street
$model->address()->postcode
$model->address()->street
$model->address()->number
$model->address()->complement
$model->address()->neighborhood
$model->address()->city
$model->address()->state
$model->address()->state_initials
$model->address()->latitude
$model->address()->longitude
Segurança
Caso encontre alguma falha de segurança, por favor, envie um email para tarsisio@fmd.ag ao invés de abrir uma issue.
Creditos
Licença
Licença MIT. Clique aqui para mais detalhes.