Skip to main content
Version: 1.x

← Previous · Back to README · Next →

Yandex

Create the files​

php artisan make:feed Yandex

Populate the feed​

Replace extends Feed with extends YandexFeedPreset in the generated class:

<?php

declare(strict_types=1);

namespace App\Feeds;

use App\Models\Product;
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
use DragonCode\LaravelFeed\Presets\YandexFeedPreset;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

use function config;

class YandexFeed extends YandexFeedPreset
{
public function builder(): Builder
{
return Product::query();
}

public function info(): FeedInfo
{
return parent::info()
->name('My App') // By default, config('app.name')
->company('My Company') // By default, config('app.name')
->platform('My Platform') // By default, config('app.name')
->url(config('app.url')) // By default, config('app.url')
->email(config('app.email', '[email protected]'))
->currencies(['RUB' => 1]) // By default, ['RUB' => 1]
->categories([
1 => 'Foo',
2 => 'Bar',
])
->additional([
'foo' => 'bar',
]);
}

public function item(Model $model): FeedItem
{
return parent::item($model)
->attributeId($model->getKey()) // By default, $model->getKey()
->attributeAvailable($model->quantity > 0) // By default, true
->attributeType('vendor.model') // By default, 'vendor.model'
->barcode($model->article) // By default, null
->url($model->url)
->title($model->title)
->description($model->description)
->price($model->price)
->currencyId('RUB') // By default, 'RUB'
->vendor($model->brand) // By default, null
->images($model->images)
->additional([
'foo' => 'bar',
]);
}

public function filename(): string
{
return 'yandex.xml';
}
}

Custom category structure​

By default, category() builds a category from its ID and name. Use rawCategory() when additional properties or another structure are required. The array is added to the feed unchanged:

use DragonCode\LaravelFeed\Presets\Info\YandexFeedInfo;

$info = (new YandexFeedInfo)
->category(1, 'Electronics')
->rawCategory([
'@attributes' => [
'id' => 2,
'parentId' => 1,
],
'@value' => 'Smartphones',
]);

The categories() method accepts both forms. It sends string values to category() and array values to rawCategory().

note

Custom category arrays are not validated or transformed. Build them with the supported XML directives.

Activate​

Review the generated operation or migration file, then run the appropriate console command:

# For Laravel Deploy Operations
php artisan operations

# For Laravel Migrations
php artisan migrate

Generate feed​

Generate the feed by running the following console command:

php artisan feed:generate

Result​

<!DOCTYPE yml_catalog SYSTEM "shops.dtd">
<yml_catalog date="2025-09-04T04:08:12+00:00">
<shop>
<name>My App</name>
<company>My Company</company>
<platform>My Platform</platform>
<url>https://example.com</url>
<email>[email protected]</email>
<currencies>
<currency id="RUB" rate="1"/>
</currencies>
<categories>
<category id="1">Foo</category>
<category id="2">Bar</category>
</categories>
<foo>bar</foo>

<offers>

<offer id="1" available="true" type="vendor.model">
<url>https://example.com/products/ea-voluptatum-fuga-odio-expedita</url>
<barcode>GD-PRDCT-1</barcode>
<name>Some 1</name>
<description>Some description 1</description>
<price>100</price>
<currencyId>RUB</currencyId>
<vendor>The Best</vendor>
<picture>https://via.placeholder.com/640x480.png/008877?text=repudiandae</picture>
<foo>bar</foo>
</offer>
<offer id="2" available="true" type="vendor.model">
<url>https://example.com/products/dolores-rerum-ut-consequatur-in</url>
<barcode>GD-PRDCT-2</barcode>
<name>Some 2</name>
<description>Some description 2</description>
<price>250</price>
<currencyId>RUB</currencyId>
<vendor>The Best</vendor>
<picture>https://via.placeholder.com/640x480.png/009966?text=beatae</picture>
<picture>https://via.placeholder.com/640x480.png/000011?text=deleniti</picture>
<picture>https://via.placeholder.com/640x480.png/009999?text=voluptates</picture>
<foo>bar</foo>
</offer>

</offers>
</shop>
</yml_catalog>

See Also​