承接 jmjl161100/laravel-relation-updater 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jmjl161100/laravel-relation-updater

最新稳定版本:v1.0.0

Composer 安装命令:

composer require jmjl161100/laravel-relation-updater

包简介

Elegant and declarative model relation updater for Laravel.

README 文档

README

License PHP Version Laravel Version

Laravel Relation Updater

Elegant and declarative model relation updater for Laravel.

✨ Features

  • ✅ Simple, expressive API for updating Eloquent relationships
  • ✅ Supports multiple relation types (hasOne, hasMany, etc.)
  • ✅ Laravel 11+ ready
  • ✅ PHP 8.2+ support
  • ✅ Returns detailed result collections: created, updated, deleted

📦 Installation

Install via Composer:

composer require jmjl161100/laravel-relation-updater

The service provider will be auto-registered via Laravel package discovery.

🚀 Quick Start

1. Use the Trait in Your Model

use Illuminate\Database\Eloquent\Model;
use Jmjl161100\RelationUpdater\Traits\HasRelationUpdater;

class Post extends Model
{
    use HasRelationUpdater;

    public function comments()
    {
        return $this->hasMany(Comment::class);
    }
}

2. Update Relations with {relationName}Update

$post = Post::find(1);

$result = $post->commentsUpdate([
    ['id' => 1, 'content' => 'Updated comment'], // Update
    ['content' => 'New comment']                // Create
]);

3. Get Operation Results

The returned result is an array of model collections:

[
    'created' => Collection, // Newly created models
    'updated' => Collection, // Updated models
    'deleted' => Collection  // Models deleted due to sync
]

⚙️ Advanced Usage

Field Mapping

If input keys differ from model attributes, provide a mapping:

$post->commentsUpdate(
                        [
                            ['id' => 1, 'input_content' => 'Updated comment']
                        ], 
                        [
                            'input_content' => 'content'
                        ]
                     );

This maps input_content to the model's content attribute.

🛡 Security

If you discover a security vulnerability, please do not open an issue. Instead, contact the author directly.

📄 License

This package is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-21