beanbean/contact

用于Laravel存储多个联系人的包

0.2.0 2020-04-04 06:26 UTC

README

Build Status

安装

composer require beanbean/contact

用法

此包支持对象的单个或多个联系人。

示例:您的用户可以有一个主要联系人,以及其他联系人用于账单、发货、以及其他次要联系人等。

与您的代码集成

  1. 在您的模型中添加 Contactable 特性
// class User
use \Bean\Contact\Traits\Contactable;
  1. 保存联系人,更新或创建新的联系人
$user->saveContact($name = 'shipping', $contact = [
    'first_name' => 'any',
    'last_name'  => 'any',
    'address'    => 'any',
    'address_2'  => 'any',
    'city'       => 'any',
    'state'      => 'any',
    'postcode'    => 'any',
    'country'    => 'any',
    'phone'      => 'any',
    'fax'        => 'any',
    'email'      => 'any',
]);
  1. 获取与联系人相关联的关系以填充联系人
$user->contacts // return all contacts of user by hasMany relationship
$user->contact($name = 'shipping')->first() // return a single shipping contact of user
$user->contact_shipping // return a shipping contact of user by magic method
  1. json api 在您的api配置文件中注册资源提供者
    'providers' => [
        \Bean\Contact\ApiResourceProvider::class,
    ],
get contact: GET contacts?filter[object_id]=1&filter[object_type]=User&filter[name]=shipping
see more https://github.com/cloudcreativity/laravel-json-api

** 如果您需要更改某些内容,请发布迁移

php artisan vendor:publish --provider "Bean\Contact\ServiceProvider"

贡献

欢迎PR。请首先打开一个issue,并提交包含良好提交信息的PR。谢谢

许可证

MIT