PHP code example of madad / laravel-sdk

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

    

madad / laravel-sdk example snippets


'product' => [
    'model'       => \App\Models\Product::class,
    'external_id' => 'id',
    'version'     => 'updated_at',
    'map' => [
        'name'  => 'listing_name',   // Madad 'name' ← your 'listing_name'
        'price' => 'unit_price',
    ],
    'category' => [
        'external_id' => 'category.code',
        'path'        => ['category.name'],
    ],
    'specifications' => ['relation' => 'attributes', 'key' => 'name', 'value' => 'value'],
    'images'         => ['relation' => 'photos', 'url' => 'url', 'sort' => 'position'],
],

public function madadPrice(): float { return $this->cents / 100; }

// Image URLs must be publicly reachable — Madad fetches and stores its own copy.
public function madadImages(): array
{
    return [
        ['url' => config('services.madad.placeholder_image'), 'sort_order' => 0],
    ];
}

public function madadImages(): array
{
    $real = $this->photos->pluck('url')->filter()->values();   // your own relation

    if ($real->isNotEmpty()) {
        return $real->map(fn ($url, $i) => ['url' => $url, 'sort_order' => $i])->all();
    }

    return [['url' => config('services.madad.placeholder_image'), 'sort_order' => 0]];
}

use Madad\Sdk\Concerns\SyncsWithMadad;

class Product extends Model
{
    use SyncsWithMadad;
}

public function shouldSyncToMadad(): bool
{
    // Only sync products under your "Building Materials" branch.
    return $this->category && $this->category->isDescendantOf($buildingMaterialsId);
}

use Madad\Sdk\Facades\Madad;

Madad::ping(); // returns your account + inherited defaults