f-liva/laravel-hasmany-sync 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

f-liva/laravel-hasmany-sync

最新稳定版本:1.2.2

Composer 安装命令:

composer require f-liva/laravel-hasmany-sync

包简介

Sync Laravel HasMany relationships with ease

README 文档

README

Latest Version on Packagist License Codecov TravisCI StyleCI

With this package you will be able to synchronize your HasMany relationships just as you normally would for BelongsToMany relationships. The usage is the same, follow the official Laravel documentation.

Thanks to korridor/laravel-has-many-sync for the original idea. This package reconstructs the mechanism using the original Laravel approach and operation.

Installation

You can install the package via composer with following command:

composer require f-liva/laravel-hasmany-sync

Usage

Configure your HasMany relationship as you normally would

class Customer extends Model
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function contacts()
    {
        return $this->hasMany(CustomerContact::class);
    }
}

Synchronize the relationship as you normally would in a BelongsToMany relationship

$customer->contacts()->sync([1, 2, 3]);

// Or with attributes...

$customer->contacts()->sync([1 => ['name' => 'Foo'], 2 => ['name' => 'Bar'], 3]);

The sync method accepts the same parameters described in Eloquent Relationships - Syncing Relations

You can also synchronize the relationship without knowing the identifiers of the related records. In this case, specify in the call the syncRelatedKey: false parameter.

$customer->contacts()->sync([1, 2, 3], syncRelatedKey: false);

// Or with attributes...

$customer->contacts()->sync([['name' => 'Foo'], ['name' => 'Bar'], ...]);

Contributing

I am open for suggestions and contributions. Just create an issue or a pull request.

Testing

The composer test command runs all tests with phpunit. The composer test-coverage command runs all tests with phpunit and creates a coverage report into the coverage folder.

Codeformatting/Linting

The composer fix command formats the code with php-cs-fixer. The composer lint command checks the code with phpcs.

License

This package is licensed under the MIT License (MIT). Please see license file for more information.

统计信息

  • 总下载量: 577
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固