Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Avito Board Laravel Package

baks-dev/avito-board

Laravel/PHP модуль baks-dev/avito-board для интеграции с Avito: публикация и управление объявлениями, поддержка PHP 8.4+. Устанавливается через Composer, есть PHPUnit-тесты (группа avito-board). Лицензия MIT.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require baks-dev/avito-board baks-dev/core:^7.4
    

    Verify php -v is 8.4+ and Laravel is 10.x (Symfony 6+ compatible).

  2. Publish Configuration:

    php artisan vendor:publish --provider="BaksDev\AvitoBoard\AvitoBoardServiceProvider" --tag="config"
    

    Edit config/avito-board.php to set:

    • api_key (Avito API credentials).
    • default_category (e.g., "notebooks").
    • cache_driver (e.g., "redis" for performance).
  3. First Integration: Use the Facade to fetch ads in a controller:

    use BaksDev\AvitoBoard\Facades\AvitoBoard;
    
    public function index()
    {
        $ads = AvitoBoard::searchAds(['category' => 'notebooks', 'limit' => 10]);
        return view('ads.index', compact('ads'));
    }
    

    Note: The facade abstracts Symfony’s AvitoBoardClient; ensure AvitoBoardServiceProvider is registered in config/app.php.

  4. Blade Template: Display ads in resources/views/ads/index.blade.php:

    @foreach($ads as $ad)
        <div class="ad-card">
            <h3>{{ $ad->title }}</h3>
            <p>{{ $ad->price }} ₽</p>
            <a href="{{ $ad->url }}">View on Avito</a>
        </div>
    @endforeach
    
  5. Route: Add to routes/web.php:

    use App\Http\Controllers\AdController;
    
    Route::get('/ads', [AdController::class, 'index']);
    

Implementation Patterns

Core Workflows

1. Ad Listing Management

  • Create/Update Ads:
    $adData = [
        'title' => 'MacBook Pro 2023',
        'price' => 120000,
        'category' => 'notebooks',
        'description' => 'Like new...',
    ];
    AvitoBoard::createAd($adData); // Returns Avito ad ID
    
  • Sync with Avito: Use Laravel Queues to batch updates:
    use Illuminate\Support\Facades\Queue;
    
    Queue::push(function () {
        AvitoBoard::syncAd($adId, $updatedData);
    });
    

2. Search and Filtering

  • Advanced Queries:
    $results = AvitoBoard::searchAds([
        'category' => 'phones',
        'price_min' => 5000,
        'price_max' => 20000,
        'region' => 'moscow',
    ]);
    
  • Pagination:
    $paginatedAds = AvitoBoard::searchAds([...], ['page' => 2, 'per_page' => 20]);
    

3. User Authentication

  • OAuth Flow (if supported):
    $authUrl = AvitoBoard::getAuthUrl(['scope' => 'ads.write']);
    // Redirect user to $authUrl, then handle callback with:
    $token = AvitoBoard::handleAuthCallback($code);
    

4. Event-Driven Updates

  • Listen for Avito Webhooks (if enabled):
    use BaksDev\AvitoBoard\Events\AdUpdated;
    
    event(new AdUpdated($adId, $changes));
    
  • Laravel Event Handling:
    // In EventServiceProvider
    protected $listen = [
        AdUpdated::class => [
            \App\Listeners\SyncLocalAd::class,
        ],
    ];
    

Integration Tips

Laravel-Symfony Bridge

  1. Service Binding: Bind Symfony services to Laravel’s container in AppServiceProvider:

    public function register()
    {
        $this->app->singleton(\BaksDev\AvitoBoard\Client\AvitoClient::class, function ($app) {
            return new \BaksDev\AvitoBoard\Client\AvitoClient(
                $app['config']['avito-board.api_key']
            );
        });
    }
    
  2. Facade Alias: Add to config/app.php:

    'aliases' => [
        // ...
        'AvitoBoard' => \BaksDev\AvitoBoard\Facades\AvitoBoard::class,
    ],
    

Performance Optimization

  • Caching API Responses:
    $ads = Cache::remember("avito_ads_{$category}", now()->addHours(1), function () use ($category) {
        return AvitoBoard::searchAds(['category' => $category]);
    });
    
  • Queue Delayed Syncs:
    Queue::later(now()->addMinutes(5), function () use ($adId) {
        AvitoBoard::syncAd($adId);
    });
    

Testing

  • Mock Avito API: Use Laravel’s HTTP testing:
    $response = Http::fake([
        'api.avito.ru/*' => Http::response([...], 200),
    ]);
    $ads = AvitoBoard::searchAds([...]);
    $response->assertSent();
    

Gotchas and Tips

Pitfalls

  1. Symfony Dependency Hell:

    • Issue: baks-dev/core may pull in Symfony components (e.g., symfony/console) that conflict with Laravel.
    • Fix: Use composer why-not to detect conflicts. Isolate in a separate service if needed.
  2. Undocumented API Limits:

    • Issue: Avito’s rate limits (e.g., 60 requests/minute) may cause 429 errors.
    • Fix: Implement retries with exponential backoff:
      use Illuminate\Support\Facades\Http;
      
      Http::timeout(30)->retry(3, 100)->get(...);
      
  3. Twig in Blade:

    • Issue: The package may use Twig templates. Laravel’s Blade is incompatible.
    • Fix: Convert templates manually or use tightenco/ziggy for URL helpers.
  4. Missing Laravel Events:

    • Issue: Symfony events (e.g., AdCreatedEvent) won’t trigger Laravel listeners.
    • Fix: Create adapters:
      AvitoBoard::onAdCreated(function ($ad) {
          event(new \App\Events\AdCreated($ad));
      });
      
  5. Database Schema Mismatch:

    • Issue: Doctrine entities may not map cleanly to Eloquent.
    • Fix: Use a separate database for Avito data or write custom migrations.

Debugging Tips

  1. Enable Avito API Logging:

    'logging' => [
        'enabled' => true,
        'path' => storage_path('logs/avito.log'),
    ],
    

    in config/avito-board.php.

  2. Symfony Debug Dump: Use dd() or dump() from symfony/var-dumper:

    use Symfony\Component\VarDumper\Cloner\VarCloner;
    use Symfony\Component\VarDumper\Dumper\CliDumper;
    
    $cloner = new VarCloner();
    $dumper = new CliDumper();
    $dumper->dump($cloner->clone($avitoResponse));
    
  3. Common Errors:

    • ClassNotFoundException: Missing baks-dev/core or Symfony components. Fix: Run composer dump-autoload.
    • InvalidArgumentException: Invalid Avito API parameters. Fix: Validate inputs with Laravel’s Validator.

Extension Points

  1. Custom Ad Fields: Extend the Ad model by adding traits:

    use BaksDev\AvitoBoard\Models\Ad as BaseAd;
    
    class Ad extends BaseAd
    {
        protected $casts = [
            'custom_field' => 'array',
        ];
    }
    
  2. Webhook Handlers: Create a Laravel command to process Avito webhooks:

    use Illuminate\Console\Command;
    use BaksDev\AvitoBoard\Events\WebhookReceived;
    
    class ProcessAvitoWebhooks extends Command
    {
        public function handle()
        {
            event(new WebhookReceived($payload));
        }
    }
    
  3. Localization: Override Russian-specific text:

    AvitoBoard::setTranslator(function ($key, $params) {
        return __("avito.{$key}", $params);
    });
    
  4. Testing Hooks: Stub Avito API responses in tests:

    AvitoBoard::shouldReceive('
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes