PHP code example of mathieutu / laravel-json-syncer

1. Go to this page and download the library: Download mathieutu/laravel-json-syncer 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/ */

    

mathieutu / laravel-json-syncer example snippets


namespace App\Models;

//...
use MathieuTu\JsonSyncer\Contracts\JsonExportable;
use MathieuTu\JsonSyncer\Traits\JsonExporter;
// or/and
use MathieuTu\JsonSyncer\Contracts\JsonImportable;
use MathieuTu\JsonSyncer\Traits\JsonImporter;

class User extends Model implements JsonExportable, JsonImportable
{
    use JsonExporter;
    use JsonImporter;
    // ...
}

Foo::first()->exportToJson(JSON_PRETTY_PRINT);

Foo::importFromJson($json);

dd(Foo::with('bars.baz')->first()->toArray());
/*
array:4 [
  "id" => 1
  "author" => null
  "username" => "@mathieutu"
  "bars" => array:1 [
    0 => array:4 [
      "id" => 1
      "name" => "my unique simple bar!"
      "foo_id" => "1"
      "baz" => null
    ]
  ]
]
*/