poojajadav/hasmanysync
最新稳定版本:2.0.0
Composer 安装命令:
composer require poojajadav/hasmanysync
包简介
This trait can be sync data for hasmany relationship.
关键字:
README 文档
README
Introduction
This package adds has-many sync relationships to Eloquent in Laravel. It's same like sync relationship.
Installation
You can install the package via composer
composer require poojajadav/hasmanysync
Usage
Hasmany sync
Hasmany-sync relation is almost identical to standard Syncing Associations except. It'll add, update and remove data from hasmany relationship. Example:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Poojajadav\Hasmanysync\Traits\HasManySync; class Post extends Model { use HasFactory; use HasManySync; protected $guarded = []; public function comments() { return $this->hasMany(Comment::class); } }
Now you can action on relationship like:
<?php $post = Post::first(); $comments = [ [ "id" => 2, "post_id" => 1, "name" => "This comment will be update" ], ['name' => 'This comment will attach'], ]; $post->comments()->sync($comments);
Contributors
统计信息
- 总下载量: 1.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-04-09