Yandex | Laravel Feeds

Laravel Feeds Help

Yandex

Create the files

php artisan make:feed Yandex -it

Populate the feed

<?php declare(strict_types=1); namespace App\Feeds; use App\Feeds\Info\YandexFeedInfo; use App\Feeds\Items\YandexFeedItem; use App\Models\Product; use DragonCode\LaravelFeed\Data\ElementData; use DragonCode\LaravelFeed\Feeds\Feed; use DragonCode\LaravelFeed\Feeds\Info\FeedInfo; use DragonCode\LaravelFeed\Feeds\Items\FeedItem; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; class YandexFeed extends Feed { public function builder(): Builder { return Product::query(); } public function root(): ElementData { return new ElementData('offers', beforeInfo: false); } public function header(): string { $date = now()->toIso8601String(); return <<<XML <!DOCTYPE yml_catalog SYSTEM "shops.dtd"> <yml_catalog date="$date"> <shop> XML; } public function footer(): string { return "</shop>\n</yml_catalog>"; } public function info(): FeedInfo { return new YandexFeedInfo; } public function item(Model $model): FeedItem { return new YandexFeedItem($model); } public function filename(): string { return 'yandex.xml'; } }

Populate the feed info

<?php declare(strict_types=1); namespace App\Feeds\Info; use DragonCode\LaravelFeed\Feeds\Info\FeedInfo; class YandexFeedInfo extends FeedInfo { public function toArray(): array { return [ 'name' => config('app.name'), 'company' => config('app.name'), 'platform' => config('app.name'), 'url' => config('app.url'), 'email' => config('emails.manager'), 'currencies' => [ '@currency' => [ [ '@attributes' => [ 'id' => 'RUR', 'rate' => '1', ], ], ], ], 'categories' => [ '@category' => [ [ '@attributes' => ['id' => 41], '@value' => 'Домашние майки', ], [ '@attributes' => ['id' => 539], '@value' => 'Велосипедки', ], ], ], ]; } }

Populate the feed item

<?php declare(strict_types=1); namespace App\Feeds\Items; use DragonCode\LaravelFeed\Feeds\Items\FeedItem; /** @property-read \App\Models\Product $model */ class YandexFeedItem extends FeedItem { public function name(): string { return 'offer'; } public function attributes(): array { return [ 'id' => $this->model->id, 'available' => ! empty($this->model->quantity) ? 'true' : 'false', 'type' => 'vendor.model', ]; } public function toArray(): array { return [ 'url' => route('products.show', $this->model->slug), 'barcode' => $this->model->article, 'name' => $this->model->title, 'description' => $this->model->description, 'delivery' => 'true', 'price' => $this->model->price, 'currencyId' => 'RUR', 'vendor' => $this->model->brand, '@picture' => $this->model->images, '@param' => [ [ '@attributes' => ['name' => 'Артикул'], '@value' => $this->model->article, ], [ '@attributes' => ['name' => 'Код цвета'], '@value' => fake()->randomDigit(), ], [ '@attributes' => ['name' => 'Пол'], '@value' => fake()->boolean() ? 'male' : 'female', ], ], ]; } }

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>Laravel</name> <company>Laravel</company> <platform>Laravel</platform> <url>https://example.com</url> <email>[email protected]</email> <currencies> <currency id="RUR" rate="1"/> </currencies> <categories> <category id="41">Домашние майки</category> <category id="539">Велосипедки</category> </categories> <offers> <offer id="1" available="true" type="vendor.model"> <url>https://example.com/products/quas-aut-omnis-dolorum-nulla-quo-nisi</url> <barcode>GD-WG&amp;$VS</barcode> <name>dolorum architecto doloremque voluptatem</name> <description>Asperiores eum ab deleniti ipsum consequatur consequatur totam dolorum. Velit amet in ducimus quis non unde. Delectus magnam et rerum aut quibusdam enim natus.</description> <delivery>true</delivery> <price>145</price> <currencyId>RUR</currencyId> <vendor>ea</vendor> <picture>https://via.placeholder.com/640x480.png/003355?text=fugiat</picture> <picture>https://via.placeholder.com/640x480.png/006622?text=laudantium</picture> <picture>https://via.placeholder.com/640x480.png/00cc88?text=reiciendis</picture> <param name="Артикул">GD-WG&amp;$VS</param> <param name="Код цвета">7</param> <param name="Пол">female</param> </offer> <offer id="2" available="false" type="vendor.model"> <url>https://example.com/products/distinctio-qui-ratione-consequatur-aspernatur-et</url> <barcode>GD-%L;]UB</barcode> <name>magnam consequatur harum cupiditate</name> <description>Harum in ratione perspiciatis quo consequatur id a. Totam magnam et est iusto amet totam minus voluptatum. In cum minima explicabo consectetur minus ex praesentium. Nemo maiores laboriosam dicta.</description> <delivery>true</delivery> <price>618</price> <currencyId>RUR</currencyId> <vendor>aut</vendor> <picture>https://via.placeholder.com/640x480.png/00bb77?text=aut</picture> <picture>https://via.placeholder.com/640x480.png/009933?text=voluptas</picture> <picture>https://via.placeholder.com/640x480.png/00eeee?text=delectus</picture> <param name="Артикул">GD-%L;]UB</param> <param name="Код цвета">5</param> <param name="Пол">male</param> </offer> </offers> </shop> </yml_catalog>
05 September 2025