New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

poojajadav/hasmanysync

This trait can be sync data for hasmany relationship.
1,524 1
Install
composer require poojajadav/hasmanysync
Latest Version:2.0.0
PHP:^8.2
Laravel:8 – 11
Older releases:5 · 6 · 7
License:MIT
Last Updated:Jun 19, 2024
Links: GitHub  ·  Packagist
Maintainer: PoojaJadav

HasMany Sync

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

Related Packages

jwohlfert23/laravel-sync-relations

Package to sync nested relations from request data

7,351 0
van-ons/laravel-translations-sync

A package that synchronizes translations between your Laravel project and a prov...

4,384 0
railroad/points

A user point tracking system, which is commonly used for tracking user XP, like...

81,941 0
railroad/event-data-synchronizer

This package has reconfigured event listeners for syncing data across packages.

56,573 0
aranyasen/laravel-env-sync

A package that makes sure that your .env file is in sync with your .env.example

22,926 4

Version History

Version Released PHP Laravel License
2.0.0 ^8.2 ^8.0 || ^9.0 || ^10.0 || ^11.0 MIT
1.0.0 >=7.2 ~5|~6|~7|~8|~9|~10 MIT