›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-data-sync
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • File identity and runs
  • Sync definitions
  • Sources and connections
  • File formats and readers
  • Field mapping
  • Matching and writing
  • Validation and hooks

Running syncs

  • Running a sync
  • Queues and workers
  • Scheduling

Transfers

  • File transfers

Operations

  • Run history and status
  • Events and listeners
  • Failures and retries
  • Sensitive data
  • Health checks
  • Retention and pruning

Reference

  • Configuration
  • Console commands
  • Testing
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • File identity and runs
  • Sync definitions
  • Sources and connections
  • File formats and readers
  • Field mapping
  • Matching and writing
  • Validation and hooks

Running syncs

  • Running a sync
  • Queues and workers
  • Scheduling

Transfers

  • File transfers

Operations

  • Run history and status
  • Events and listeners
  • Failures and retries
  • Sensitive data
  • Health checks
  • Retention and pruning

Reference

  • Configuration
  • Console commands
  • Testing
  • Troubleshooting

byrcsc/laravel-data-sync · 1.x

Quick start.

Import a supplier CSV into an Eloquent model and inspect the recorded run.

This walkthrough imports two products from a CSV file. It assumes Laravel Data Sync is installed and its database tables are migrated.

1. Create the file and definition

Place this file at products/products-2026-07-31.csv on the incoming disk:

SKU,Description,Price,Currency
DS-1001,Anglepoise desk lamp,89.00,PHP
DS-1002,Mechanical keyboard,149.50,PHP

Generate a definition class:

php artisan make:sync ProductsSync

The command writes app/Syncs/ProductsSync.php.

2. Describe the import

Update the generated class:

namespace App\Syncs;

use App\Models\Product;
use ByRcsc\LaravelDataSync\Contracts\Reader as ReaderContract;
use ByRcsc\LaravelDataSync\Definitions\Field;
use ByRcsc\LaravelDataSync\Definitions\Reader;
use ByRcsc\LaravelDataSync\Definitions\Source;
use ByRcsc\LaravelDataSync\Definitions\SyncDefinition;

final class ProductsSync extends SyncDefinition
{
    public function source(): Source
    {
        return Source::disk('incoming')->path('products');
    }

    public function format(): ReaderContract
    {
        return Reader::csv();
    }

    public function model(): string
    {
        return Product::class;
    }

    public function fields(): array
    {
        return [
            Field::make('sku', from: 'SKU'),
            Field::make('name', from: 'Description'),
            Field::make('price_cents', from: 'Price')
                ->transform(
                    fn (string $value): int =>
                        (int) round((float) $value * 100),
                ),
            Field::make('currency')->default('PHP'),
        ];
    }

    public function matchOn(): array
    {
        return ['sku'];
    }

    public function rules(): array
    {
        return [
            'sku' => ['required', 'string', 'max:32'],
            'price_cents' => ['required', 'integer', 'min:0'],
        ];
    }
}

The definition reads CSV files from the products directory. It maps source columns to model attributes and uses sku to find an existing product.

Add a unique database index for products.sku. The health check warns when a matching column has no unique index.

3. Register and run the sync

Register the class in config/data-sync.php:

'syncs' => [
    App\Syncs\ProductsSync::class,
],

Run the first import in the current process:

php artisan sync:run products --now
Running [products]...
  File run [01JQ8Z3M0K2N4P6R8T0V2X4Y6A] (bulk) ... 2 created, 0 updated, 0 skipped, 0 failed
[products] finished: 1 discovered, 0 skipped, 0 deferred.

ProductsSync becomes the command name products. Override name() when you need another name.

Run the command again without changing the file. The checksum is already in the ledger, so the command skips it instead of importing the rows twice.

4. Inspect the recorded run

php artisan sync:status products --limit=25

The output shows the run identifier, status, write path, and row counters:

  Run                          Sync      Status · path        C/U/S/F   Progress
  01JQ8Z3M0K2N4P6R8T0V2X4Y6A   products  completed · bulk     2/0/0/0   2 rows

Use the run identifier when you need to inspect failures or retry an attempt.

What to read next

  • Sync definitions for every setting a definition can provide.
  • Field mapping for transforms, defaults, and optional columns.
  • Matching and writing for write modes, duplicate handling, and transactions.
  • Queues and workers to process large files outside the command process.
  • Failures and retries to inspect and replay failed rows.
PreviousInstallation and setupNextFile identity and runs
View source

On this page

  1. 1. Create the file and definition
  2. 2. Describe the import
  3. 3. Register and run the sync
  4. 4. Inspect the recorded run
  5. What to read next