zoparga / laravel-contact-information
使用单个特性向多个模型添加多个地址。例如:为顾客添加多个收货地址。
0.8.1
2022-04-27 13:26 UTC
Requires
- php: ^7.3|^8.0
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.15
- pestphp/pest: ^1.18
- pestphp/pest-plugin-laravel: ^1.1
- spatie/laravel-ray: ^1.23
- vimeo/psalm: ^4.8
README
安装
您可以通过composer安装此包
composer require zoparga/laravel-contact-information
您可以使用以下命令发布并运行迁移
php artisan vendor:publish --provider="zoparga\ContactInformation\ContactInformationServiceProvider" --tag="contact-information-migrations" php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="zoparga\ContactInformation\ContactInformationServiceProvider" --tag="laravel-contact-information-config"
这是已发布的配置文件内容
用法
- 发布迁移文件
- 迁移
- 将特性添加到模型
- 使用它
准备模型
使用 zoparga\ContactInformation\Traits\ContactInformationeableTrait;
class {{model}} extends Model { use ContactInformationeableTrait; }
$model = \App\Models\Model::find(1); $model->contactInformations()->create([ 'type' => 'phone', 'information' => '+361123123', 'primary' => 1, ]); $model->contactInformations()->create([ 'type' => 'web', 'information' => 'info.xyz', 'primary' => 1, ]); $contactInformationId = 1; $model->updateContactInformation($contactInformationId, [ 'type' => 'phone', 'information' => '+361123123', 'primary' => 0, ]); Get the addresses, order by ID - desc Or you can limit it here $model->getLatestContactInformationes()->get(); Or you can limit it here $model->getLatestContactInformationes()->limit(3)->get(); Of course you can get last created address $model->getLastContactInformation();
测试
composer test
变更日志
请参阅变更日志以获取有关最近更改的更多信息。
贡献
请参阅贡献指南以获取详细信息。
安全漏洞
请查看我们的安全策略以了解如何报告安全漏洞。
鸣谢
许可
MIT许可(MIT)。请参阅许可文件以获取更多信息。