agenciafmd/admix-addresses

此软件包的最新版本(1.0.0)没有可用的许可证信息。

地址 - F&MD 机构

1.0.0 2020-01-14 20:55 UTC

This package is auto-updated.

Last update: 2024-09-07 19:06:10 UTC


README

Área administrativa

Downloads Licença

  • 将地址/地图字段与模型关联

安装

composer require agenciafmd/admix-addresses:dev-master

配置

模型

在模型 Package.php 中添加 Trait$guarded

use Agenciafmd\Addresses\Traits\AddressTrait;
...
class Package extends Model implements AuditableContract
...
    use AddressTrait
...
    protected $guarded = [
        ...'address',...
    ];

视图(待:重构为 blade 组件)

在将要实现的地址视图上添加

@include('agenciafmd/addresses::default')

如果需要自定义,请添加

@include('agenciafmd/addresses::default', ['title' => 'Endereço do Ponto de Venda', 'collection' => 'pos'])

也将脚本添加到 @push('scripts')

@push('scripts')
    @include('agenciafmd/addresses::scripts')
@endpush

验证

Http/Requests/PackageRequest.php 中添加

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',
        ...
    ];
}

工厂(待:重构说明如何使用)

...
$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),
]);
...

使用

当需要时,调用数据

$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

安全性

如果发现任何安全漏洞,请通过发送电子邮件到 tarsisio@fmd.ag 而不是通过开启一个 issue。

贡献者

许可

MIT 许可证。 点击此处 了解更多详情。