PHP code example of elbgoods / eloquent-sync-one-to-many

1. Go to this page and download the library: Download elbgoods/eloquent-sync-one-to-many library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

elbgoods / eloquent-sync-one-to-many example snippets

 php
$user->tasks()->sync([1, 2, 4]);
 php
$user->tasks()->syncWithoutDetaching([1, 2, 4]);

// or

$user->tasks()->sync([1, 2, 4], ['detaching' => false]);
 php
$user->tasks()->sync(
    [1, 2, 4],
    'set_after_detach' => [
        'status' => 'open',
        'priority' => 0,
    ],
);