### Install and prepare the package Source: https://feeds.dragon-code.pro/introduction Run these commands to install the package, publish configuration, and prepare the database. ```bash composer require dragon-code/laravel-feeds php artisan vendor:publish --tag="feeds" php artisan migrate php artisan make:feed User --item ``` -------------------------------- ### Generated File Paths Source: https://feeds.dragon-code.pro/receipt-target-feeds Example output paths for available and unavailable targets. ```text storage/app/public/products/available.xml storage/app/public/products/unavailable.xml ``` -------------------------------- ### Root Sitemap Index Example Source: https://feeds.dragon-code.pro/receipt-sitemap Example structure for a root sitemap index file referencing individual sitemaps. ```xml https://example.com/sitemaps/products.xml https://example.com/sitemaps/other-sitemaps.xml ``` -------------------------------- ### Activate Feed Operations Source: https://feeds.dragon-code.pro/receipt-sitemap Run migrations or operations to finalize the feed setup. ```bash # For Laravel Deploy Operationsphp artisan operations# For Laravel Migrationsphp artisan migrate ``` -------------------------------- ### Install Laravel Feeds via Composer Source: https://feeds.dragon-code.pro/installation Use this command to add the package to your Laravel project. ```bash composer require dragon-code/laravel-feeds ``` -------------------------------- ### Extend Feed Presets Source: https://feeds.dragon-code.pro/presets Examples of extending various preset classes to create custom feed implementations. ```php use DragonCode avelFeed esets stagramFeedPreset;use DragonCode avelFeed esets ssFeedPreset;use DragonCode avelFeed esets itemapFeedPreset;use DragonCode avelFeed esets andexFeedPreset;class ProductFeed extends InstagramFeedPreset {}class ProductFeed extends YandexFeedPreset {}class ProductFeed extends SitemapFeedPreset {}class ProductFeed extends RssFeedPreset {} ``` -------------------------------- ### RSS Feed Output Example Source: https://feeds.dragon-code.pro/receipt-instagram The resulting XML structure generated by the feed command. ```xml Laravel https://example.com 1 https://example.com/products/ea-voluptatum-fuga-odio-expedita https://via.placeholder.com/640x480.png/008877?text=repudiandae https://via.placeholder.com/640x480.png/008877?text=repudiandae The Best new in stock 100 100 12345 active 123 456 Some foo Some bar Some baz a b c 2 https://example.com/products/dolores-rerum-ut-consequatur-in https://via.placeholder.com/640x480.png/009966?text=beatae https://via.placeholder.com/640x480.png/009966?text=beatae https://via.placeholder.com/640x480.png/000011?text=deleniti https://via.placeholder.com/640x480.png/009999?text=voluptates The Best new in stock 250 250 12345 active 123 456 Some foo Some bar Some baz a b c ``` -------------------------------- ### Default Feed File Naming Source: https://feeds.dragon-code.pro/location Examples of how feed class names are automatically converted to kebab-case filenames. ```text # App\Feeds\UserFeeduser-feed.xml# App\Feeds\Sitemaps\ProductFeedsitemaps-product-feed.xml ``` -------------------------------- ### View generated Yandex feed XML Source: https://feeds.dragon-code.pro/receipt-yandex Example of the final Yandex Market Language (YML) output structure. ```xml My AppMy CompanyMy Platformhttps://example.com[email protected] Foo Barbar https://example.com/products/ea-voluptatum-fuga-odio-expedita GD-PRDCT-1 Some 1 Some description 1 100 RUR The Best https://via.placeholder.com/640x480.png/008877?text=repudiandae bar https://example.com/products/dolores-rerum-ut-consequatur-in GD-PRDCT-2 Some 2 Some description 2 250 RUR The Best https://via.placeholder.com/640x480.png/009966?text=beatae https://via.placeholder.com/640x480.png/000011?text=deleniti https://via.placeholder.com/640x480.png/009999?text=voluptates bar ``` -------------------------------- ### Run database migrations Source: https://feeds.dragon-code.pro/installation Executes the migrations to set up the necessary database tables. ```bash php artisan migrate ``` -------------------------------- ### Configure Filesystem Links Source: https://feeds.dragon-code.pro/receipt-sitemap Add the sitemap directory to the links configuration in config/filesystems.php. ```php return [ 'links' => [ public_path('storage') => storage_path('app/public'), public_path('sitemaps') => storage_path('app/public/sitemaps'), ],]; ``` -------------------------------- ### Create a feed class Source: https://feeds.dragon-code.pro/create-feeds Use the make:feed command to generate a new feed file. ```bash php artisan make:feed ``` -------------------------------- ### Apply code style formatting Source: https://feeds.dragon-code.pro/contributions Run this command to automatically apply the project's coding standards. ```bash composer style ``` -------------------------------- ### Create feed file Source: https://feeds.dragon-code.pro/receipt-rss-atom Use the artisan command to generate the initial feed class. ```bash php artisan make:feed Rss ``` -------------------------------- ### Publish package assets Source: https://feeds.dragon-code.pro/installation Publishes the migration and configuration files to your project. ```bash php artisan vendor:publish --tag="feeds" ``` -------------------------------- ### Create feed classes with shortcuts Source: https://feeds.dragon-code.pro/create-feeds Use shorthand flags to generate feed classes with associated item or info classes. ```bash # Create a feed class and item class php artisan make:feed -t # Create a feed class and info class php artisan make:feed -i # Create a feed class, item class, and info class php artisan make:feed -it ``` -------------------------------- ### Implement ProductFeed Class Source: https://feeds.dragon-code.pro/receipt-sitemap Define the feed logic by extending SitemapFeedPreset and configuring the builder and item methods. ```php url($model->url) ->modifiedAt($model->updated_at) // By default, $model->updated_at ->priority(0.9); // By default, 0.9 } public function filename(): string { return 'sitemaps/' . parent::filename(); }} ``` -------------------------------- ### Create Public Symlink Source: https://feeds.dragon-code.pro/receipt-sitemap Execute the command to create the symbolic link for public access. ```bash php artisan storage:link ``` -------------------------------- ### Configure Feed Queue Environment Variables Source: https://feeds.dragon-code.pro/generation Set these environment variables to enable and configure queue-based feed generation. ```text FEED_QUEUE_ENABLED=trueFEED_QUEUE_CONNECTION=redisFEED_QUEUE_NAME=feedsFEED_QUEUE_UNIQUE_TTL=3600 ``` -------------------------------- ### Configure ProductFeed with targets Source: https://feeds.dragon-code.pro/receipt-target-feeds Implementation of a feed class using InteractsWithFeedTargets to define multiple output files based on stock status. ```php ['in_stock' => true], 'unavailable' => ['in_stock' => false], ]; public function targets(): iterable { foreach (array_keys(self::TARGETS) as $key) { yield $this->makeTarget($key); } } public function findTarget(string $key): ?FeedTarget { return isset(self::TARGETS[$key]) ? $this->makeTarget($key) : null; } public function builder(): Builder { return Product::query()->where( 'in_stock', $this->target()->parameters['in_stock'], ); } public function filename(): string { return "products/{$this->target()->key}.xml"; } private function makeTarget(string $key): FeedTarget { return new FeedTarget( key : $key, parameters: self::TARGETS[$key], ); } } ``` -------------------------------- ### Update package dependencies and run migrations Source: https://feeds.dragon-code.pro/upgrade-guide Execute these commands to update the package to the latest version and apply any necessary database schema changes. ```bash composer update dragon-code/laravel-feeds --with-all-dependenciesphp artisan migrate ``` -------------------------------- ### Create feed classes with options Source: https://feeds.dragon-code.pro/create-feeds Generate feed classes along with item and info classes using specific flags. ```bash # Create a feed class and info class php artisan make:feed --info # Create a feed class and item class php artisan make:feed --item # Create a feed class, item class, and info class php artisan make:feed --item --info ``` -------------------------------- ### Activate Laravel Operations or Migrations Source: https://feeds.dragon-code.pro/receipt-instagram Run these commands after reviewing generated operation or migration files. ```bash # For Laravel Deploy Operations php artisan operations # For Laravel Migrations php artisan migrate ``` -------------------------------- ### Generate Feed Class Source: https://feeds.dragon-code.pro/receipt-sitemap Use the artisan command to scaffold the feed and item classes. ```bash php artisan make:feed Sitemaps/Product ``` -------------------------------- ### Configure root element order relative to info Source: https://feeds.dragon-code.pro/elements Use the beforeInfo parameter in the root method to control the output order of the root element. ```php namespace App\Feeds;use App\Feeds\Info\InfoMethodFeedInfo;use App\Models\User;use DragonCode\LaravelFeed\Data\ElementData;use DragonCode\LaravelFeed\Feeds\Feed;use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;use Illuminate\Database\Eloquent\Builder;class InfoMethodBeforeFalseTest extends Feed{ public function builder(): Builder { return User::query(); } public function root(): ElementData { return new ElementData( name : 'info_method', beforeInfo: false ); } public function info(): FeedInfo { return new InfoMethodFeedInfo; }} ``` -------------------------------- ### Implement Feed Methods Source: https://feeds.dragon-code.pro/presets Implementation of the required builder and item methods within a feed class extending a preset. ```php namespace App\Feeds;use App\Models\Product;use DragonCode\LaravelFeed\Feeds\Items\FeedItem;use DragonCode\LaravelFeed\Presets\InstagramFeedPreset;use Illuminate\Database\Eloquent\Builder;use Illuminate\Database\Eloquent\Model;class InstagramFeed extends InstagramFeedPreset{ public function builder(): Builder { return Product::query(); } public function item(Model $model): FeedItem { return parent::item($model) ->title($model->title) ->description($model->description) ->brand($model->brand) // By default, null ->url($model->url) ->price(price: $model->price, salePrice: $model->price) // By default, salePrice = price ->image($model->images[0]) ->images($model->images) // By default, null ->availability($model->quantity > 0 ? 'in stock' : 'out of stock') // By default, 'in stock' ->status($model->quantity > 0 ? 'active' : 'inactive') // By default, 'active' ->condition('new') // By default, 'new' ->group(12345) // By default, null ->googleCategory(123) // By default, null ->facebookCategory(456) // By default, null ->additional([ 'g:foo' => 'Some foo', 'g:bar' => 'Some bar', 'g:baz' => [ '@attributes' => ['qwe' => 'rty'], '@value' => 'Some baz', ], '@g:arrayable' => [ 'a', 'b', 'c', ], ]); }} ``` -------------------------------- ### Generate the feed file Source: https://feeds.dragon-code.pro/introduction Execute the artisan command to generate the feed files based on defined classes. ```bash php artisan feed:generate ``` -------------------------------- ### Generate Yandex Feed Class Source: https://feeds.dragon-code.pro/receipt-yandex Run this Artisan command to scaffold the initial feed class structure. ```bash php artisan make:feed Yandex ``` -------------------------------- ### Generate Instagram Feed Class Source: https://feeds.dragon-code.pro/receipt-instagram Use the artisan command to scaffold the initial feed class. ```bash php artisan make:feed Instagram ``` -------------------------------- ### Populate the feed class Source: https://feeds.dragon-code.pro/receipt-rss-atom Extend RssFeedPreset and implement the builder and item methods to define feed content. ```php take(2); } public function item(Model $model): FeedItem { return parent::item($model) ->guid($model->id) // By default, $model->getKey() ->title($model->title) ->description($model->content) ->category($model->category) ->url($model->url) ->publishedAt($model->updated_at) // By default, $model->created_at ?? Carbon::now() ->additional(['foo' => 'bar']); // By default, [] } public function filename(): string { return 'rss.xml'; }} ``` -------------------------------- ### Create Feed Records Source: https://feeds.dragon-code.pro/eloquent Use FeedQuery or standard Eloquent methods to create records, passing extra attributes as needed. ```php $feed = app(FeedQuery::class)->create( class: SomeFeed::class, title: 'Some', expression: '0 */12 * * *', extra: [ 'is_foo' => true, 'is_bar' => true, ]); ``` ```php use App\Models\Feed;$feed = Feed::create([ 'class' => SomeFeed::class, 'title' => 'Some', 'expression' => '0 */12 * * *', 'is_active' => true, 'is_foo' => true, 'is_bar' => true,]); ``` -------------------------------- ### Implement Instagram Feed Preset Source: https://feeds.dragon-code.pro/receipt-instagram Extend InstagramFeedPreset and define the builder and item mapping logic to populate the feed. ```php title($model->title) ->description($model->description) ->brand($model->brand) // By default, null ->url($model->url) ->price(price: $model->price, salePrice: $model->price) // By default, salePrice = price ->image($model->images[0]) ->images($model->images) // By default, null ->availability($model->quantity > 0 ? 'in stock' : 'out of stock') // By default, 'in stock' ->status($model->quantity > 0 ? 'active' : 'inactive') // By default, 'active' ->condition('new') // By default, 'new' ->group(12345) // By default, null ->googleCategory(123) // By default, null ->facebookCategory(456) // By default, null ->additional([ 'g:foo' => 'Some foo', 'g:bar' => 'Some bar', 'g:baz' => [ '@attributes' => ['qwe' => 'rty'], '@value' => 'Some baz', ], '@g:arrayable' => [ 'a', 'b', 'c', ], ]); } public function filename(): string { return 'instagram.xml'; }} ``` -------------------------------- ### Implement a feed class Source: https://feeds.dragon-code.pro/create-feeds Define the query builder and item mapping within a feed class. ```php namespace App\Feeds;use App\Feeds\Items\UserFeedItem;use App\Models\User;use DragonCode\LaravelFeed\Feeds\Feed;use DragonCode\LaravelFeed\Feeds\Items\FeedItem;use Illuminate\Database\Eloquent\Builder;use Illuminate\Database\Eloquent\Model;class UserFeed extends Feed{ public function builder(): Builder { return User::query() ->whereNotNull('email_verified_at') ->where('created_at', '>', now()->subYear()); } public function item(Model $model): FeedItem { return new UserFeedItem($model); }} ``` -------------------------------- ### Implement Yandex Feed Class Source: https://feeds.dragon-code.pro/receipt-yandex Extend YandexFeedPreset to define the query builder, feed metadata, and item attribute mapping. Ensure the class is placed in the appropriate namespace. ```php 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(['RUR' => 1]) // By default, ['RUR' => 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('RUR') // By default, 'RUR' ->vendor($model->brand) // By default, null ->images($model->images) ->additional([ 'foo' => 'bar', ]); } public function filename(): string { return 'yandex.xml'; }} ``` -------------------------------- ### Split Files by Record Count Source: https://feeds.dragon-code.pro/receipt-target-feeds Implement the perFile method to define the maximum number of records per generated file. ```php public function perFile(): int { return 50000; } ``` -------------------------------- ### Split output files Source: https://feeds.dragon-code.pro/performance Define the number of records per file to manage large exports more effectively. ```php public function perFile(): int{ return 50000;} ``` -------------------------------- ### Register Feed with Fluent Expression Source: https://feeds.dragon-code.pro/generation Use the Expression class to define a schedule for a feed registration fluently. ```php use App eeds\ProductFeed;use DragonCode\LaravelFeed\Queries\FeedQuery;use DragonCode\LaravelFeed\Scheduling\Expression;app(FeedQuery::class)->create( class: ProductFeed::class, title: 'Products', expression: (new Expression) ->weekly() ->mondays() ->at('13:00'),); ``` -------------------------------- ### Generated Sitemap Output Source: https://feeds.dragon-code.pro/receipt-sitemap The resulting XML structure for the product sitemap. ```xml https://example.com/products/ea-voluptatum-fuga-odio-expedita 2025-08-31T20:00:00+00:00 0.9 https://example.com/products/dolores-rerum-ut-consequatur-in 2025-08-30T19:00:00+00:00 0.9 ``` -------------------------------- ### Generate Feed Targets via Artisan Source: https://feeds.dragon-code.pro/feed-targets Commands to trigger the generation of feed targets, either for all targets or specific ones identified by their keys. ```bash php artisan feed:generate 123 ``` ```bash php artisan feed:generate 123 --target=42php artisan feed:generate 123 --target=42 --target=81 ``` -------------------------------- ### Apply conditional logic with when and default Source: https://feeds.dragon-code.pro/extending-functionality Executes the callback if the condition is true, or the default closure if the condition is false. ```php use DragonCode\LaravelFeed\Feeds\Feed;use DragonCode\LaravelFeed\Feeds\Items\FeedItem;use Illuminate\Database\Eloquent\Model;class ProductFeed extends Feed{ public function item(Model $model): FeedItem { return (new ProductFeedItem($model)) ->when( value : $model->category, callback: function (ProductFeedItem $item) { $item->title .= ' (first)'; }, default : function (ProductFeedItem $item) { $item->title .= ' (second)'; }, ); }} ``` -------------------------------- ### Define the feed data source Source: https://feeds.dragon-code.pro/introduction Create a feed class extending the base Feed class to define the Eloquent builder and item mapping. ```php namespace App\Feeds; use App\Feeds\Items\UserFeedItem; use App\Models\User; use DragonCode\LaravelFeed\Feeds\Feed; use DragonCode\LaravelFeed\Feeds\Items\FeedItem; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; class UserFeed extends Feed { public function builder(): Builder { return User::query() ->whereNotNull('email_verified_at') ->where('created_at', '>', now()->subYear()); } public function item(Model $model): FeedItem { return new UserFeedItem($model); } } ``` -------------------------------- ### Implement feed information block Source: https://feeds.dragon-code.pro/elements Define feed information by overriding the info method and extending the FeedInfo class. ```php namespace App\Feeds;use App\Feeds\Info\InfoMethodFeedInfo;use App\Models\User;use DragonCode\LaravelFeed\Feeds\Feed;use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;use Illuminate\Database\Eloquent\Builder;class InfoMethodFeed extends Feed{ public function builder(): Builder { return User::query(); } public function info(): FeedInfo { return new InfoMethodFeedInfo; }} ``` ```php namespace App\Feeds\Info;use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;use function config;class InfoMethodFeedInfo extends FeedInfo{ public function toArray(): array { return [ 'company' => config('app.name'), 'url' => config('app.url'), ]; }} ``` -------------------------------- ### Implement file splitting in AttributeFeed Source: https://feeds.dragon-code.pro/elements Define perFile and maxFiles methods within a Feed class to restrict the number of records per file and the total number of files generated. ```php namespace App\Feeds;use App\Models\User;use DragonCode\LaravelFeed\Feeds\Feed;use Illuminate\Database\Eloquent\Builder;class AttributeFeed extends Feed{ public function builder(): Builder { return User::query(); } public function perFile(): int { return 100; } public function maxFiles(): int { return 10; }} ``` -------------------------------- ### Adding custom methods to Feed Source: https://feeds.dragon-code.pro/extending-functionality Register a custom method on the Feed class within a service provider's boot method. ```php use DragonCode\LaravelFeed\Feeds\Feed;use Illuminate\Support\ServiceProvider;class FeedServiceProvider extends ServiceProvider{ public function boot(): void { Feed::macro('customFilename', function (Feed $feed, string $name) { $this->filename = $name; return $this; }); }} ``` -------------------------------- ### Configure chunk size Source: https://feeds.dragon-code.pro/performance Override the default chunk size to balance memory usage and query overhead based on production data. ```php public function chunkSize(): int{ return 500;} ``` -------------------------------- ### XML output for custom root element Source: https://feeds.dragon-code.pro/elements The resulting XML structure after defining a custom root element. ```xml 1 User 1 2 User 2 ``` -------------------------------- ### Apply conditional logic with unless Source: https://feeds.dragon-code.pro/extending-functionality Executes the callback if the condition is false, or the default closure if the condition is true. ```php use DragonCode\LaravelFeed\Feeds\Feed;use DragonCode\LaravelFeed\Feeds\Items\FeedItem;use Illuminate\Database\Eloquent\Model;class ProductFeed extends Feed{ public function item(Model $model): FeedItem { return (new ProductFeedItem($model)) ->unless( value : $model->category, callback: function (ProductFeedItem $item) { $item->title .= ' (second)'; }, default : function (ProductFeedItem $item) { $item->title .= ' (first)'; }, ); }} ``` -------------------------------- ### Implement SitemapFeedItem Source: https://feeds.dragon-code.pro/presets Defines the structure for Sitemap feed items, mapping model data to loc, lastmod, and priority fields. ```php namespace DragonCode\LaravelFeed\Presets\Items;use Carbon\Carbon;use DragonCode\LaravelFeed\Feeds\Items\FeedItem;/** @property-read \Illuminate\Database\Eloquent\Model $model */class SitemapFeedItem extends FeedItem{ protected string $url; protected string $modifiedAt; protected float $priority = 0.9; public function name(): string { return 'url'; } public function url(string $url): static { $this->url = $url; return $this; } public function modifiedAt(Carbon $updatedAt): static { $this->modifiedAt = $updatedAt->toIso8601String(); return $this; } public function priority(float $priority): static { $this->priority = $priority; return $this; } public function toArray(): array { return [ 'loc' => $this->url, 'lastmod' => $this->modifiedAt, 'priority' => $this->priority, ]; }} ``` -------------------------------- ### Register Custom Model in Configuration Source: https://feeds.dragon-code.pro/eloquent Update the feeds configuration file to point to the custom application model. ```php 'model' => App\Models\Feed::class, ``` -------------------------------- ### Generate selected feed targets Source: https://feeds.dragon-code.pro/generation Uses the --target option to generate specific output files for a feed. Multiple targets can be specified by repeating the option. ```bash php artisan feed:generate 123 --target=42 php artisan feed:generate 123 --target=42 --target=81 ``` -------------------------------- ### Define the feed item structure Source: https://feeds.dragon-code.pro/introduction Implement the item class to define how model data is mapped to the feed output. ```php namespace App\Feeds\Items; use DragonCode\LaravelFeed\Feeds\Items\FeedItem; /** @property-read \App\Models\User $model */ class UserFeedItem extends FeedItem { public function toArray(): array { return [ 'name' => $this->model->name, 'email' => $this->model->email, ]; } } ``` -------------------------------- ### Apply prepended transformers to a feed Source: https://feeds.dragon-code.pro/extending-functionality Override the transformers() method in a Feed class to prepend custom logic before global transformers execute. ```php namespace App\Feeds;use App\Feeds\Transformers\FeedDateTimeTransformer;use App\Models\Product;use DragonCode\LaravelFeed\Feeds\Feed;use Illuminate\Database\Eloquent\Builder;class ProductFeed extends Feed{ public function builder(): Builder { return Product::query(); } public function transformers(): array { return [ FeedDateTimeTransformer::class, ]; }} ``` -------------------------------- ### Adding custom methods to FeedInfo Source: https://feeds.dragon-code.pro/extending-functionality Extend FeedInfo with custom logic accessible within the class instance. ```php use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;use Illuminate\Support\ServiceProvider;class FeedServiceProvider extends ServiceProvider{ public function boot(): void { FeedInfo::macro('titleWithPrefix', function () { return sprintf('[%s]: %s', date('Y'), $this->title); }); }}class ProductFeedInfo extends FeedInfo{ public function __construct( protected string $title, ) {} public function toArray(): array { return [ 'title' => $this->titleWithPrefix(), ]; }} ``` -------------------------------- ### Register custom transformers in configuration Source: https://feeds.dragon-code.pro/extending-functionality Add custom transformer classes to the transformers array in config/feeds.php to include them in the global pipeline. ```php [ Transformers\BoolTransformer::class, Transformers\DateTimeTransformer::class, Transformers\EnumTransformer::class, PriceTransformer::class, ],]; ``` -------------------------------- ### Generate Filtered Feed Files Source: https://feeds.dragon-code.pro/receipt-target-feeds Use the --target option to generate files for specific targets only. ```bash php artisan feed:generate 123 --target=available php artisan feed:generate 123 --target=available --target=unavailable ``` -------------------------------- ### Use @mixed directive for raw XML Source: https://feeds.dragon-code.pro/directives Injects XML fragments directly into the feed item structure using the @mixed key. ```php namespace App\Feeds\Items;use DragonCode\LaravelFeed\Feeds\Items\FeedItem;class MixedDirectiveFeedItem extends FeedItem{ public function toArray(): array { return [ 'name' => $this->model->name, '@mixed' => << Foo {$this->model->email} XML, ]; }} ``` ```xml User 1 Foo [email protected] User 2 Foo [email protected] ``` -------------------------------- ### Create a feed-specific transformer Source: https://feeds.dragon-code.pro/extending-functionality Extend existing transformer classes to override formatting logic for specific feed requirements. ```php namespace App\Feeds\Transformers;use DragonCode\LaravelFeed\Transformers\DateTimeTransformer;class FeedDateTimeTransformer extends DateTimeTransformer{ protected function format(): string { return 'Y-m-d'; }} ``` -------------------------------- ### Return an Eloquent Builder Source: https://feeds.dragon-code.pro/performance Return an Eloquent Builder directly to ensure the query remains lazy and avoids materializing the entire result set. ```php public function builder(): Builder{ return Product::query() ->select(['id', 'title', 'updated_at']) ->where('is_exportable', true);} ``` -------------------------------- ### Implement a feed item class Source: https://feeds.dragon-code.pro/create-feeds Define the structure of a feed item by implementing the toArray method. ```php namespace App\Feeds\Items;use DragonCode\LaravelFeed\Feeds\Items\FeedItem;/** @property-read \App\Models\User $model */class UserFeedItem extends FeedItem{ public function toArray(): array { return [ 'name' => $this->model->name, 'email' => $this->model->email, ]; }} ``` -------------------------------- ### Use @custom directive for repeated keys Source: https://feeds.dragon-code.pro/directives Allows listing multiple elements with the same key by prefixing the key name with @. ```php namespace App\Feeds\Items;use DragonCode\LaravelFeed\Feeds\Items\FeedItem;use function fake;class ArrayDirectiveFeedItem extends FeedItem{ public function toArray(): array { return [ 'name' => $this->model->name, '@avatar' => [ fake()->imageUrl(), fake()->imageUrl(), ], '@images' => [ [ '@attributes' => ['name' => fake()->words(asText: true)], '@value' => fake()->imageUrl(), ], [ '@attributes' => ['name' => fake()->words(asText: true)], '@value' => fake()->imageUrl(), ], ], ]; }} ``` ```xml User 1 https://via.placeholder.com/640x480.png/00ffff?text=aut https://via.placeholder.com/640x480.png/0022dd?text=et https://via.placeholder.com/640x480.png/0099dd?text=ea https://via.placeholder.com/640x480.png/00cc77?text=sint User 2 https://via.placeholder.com/640x480.png/00ff99?text=est https://via.placeholder.com/640x480.png/003300?text=non https://via.placeholder.com/640x480.png/0099aa?text=accusantium https://via.placeholder.com/640x480.png/0099cc?text=ab ``` -------------------------------- ### Implement YandexFeedItem Source: https://feeds.dragon-code.pro/presets Defines the structure for Yandex feed items, including attributes like price, currency, and vendor information. ```php namespace DragonCode\LaravelFeed\Presets\Items;use DragonCode\LaravelFeed\Feeds\Items\FeedItem;use function blank;use function collect;/** @property-read \Illuminate\Database\Eloquent\Model $model */class YandexFeedItem extends FeedItem{ protected int|string|null $attributeId = null; protected bool $attributeAvailable = true; protected string $attributeType = 'vendor.model'; protected string $url; protected ?string $barcode = null; protected string $title; protected string $description; protected string $price; protected string $currencyId = 'RUR'; protected ?string $vendor = null; protected array $images; protected array $additional = []; public function name(): string { return 'offer'; } public function attributeId(int|string|null $id): static { $this->attributeId = $id; return $this; } public function attributeAvailable(bool $available): static { $this->attributeAvailable = $available; return $this; } public function attributeType(string $type): static { $this->attributeType = $type; return $this; } public function url(string $url): static { $this->url = $url; return $this; } public function barcode(string $barcode): static { $this->barcode = $barcode; return $this; } public function title(string $title): static { $this->title = $title; return $this; } public function description(string $description): static { $this->description = $description; return $this; } public function price(float|string $price): static { $this->price = (string) $price; return $this; } public function currencyId(string $currencyId): static { $this->currencyId = $currencyId; return $this; } public function vendor(?string $vendor): static { $this->vendor = $vendor; return $this; } public function images(array $images): static { $this->images = $images; return $this; } public function additional(array $additional): static { $this->additional = $additional; return $this; } public function attributes(): array { return [ 'id' => $this->attributeId, 'available' => $this->attributeAvailable, 'type' => $this->attributeType, ]; } public function toArray(): array { return collect([ 'url' => $this->url, 'barcode' => $this->barcode, 'name' => $this->title, 'description' => $this->description, 'price' => $this->price, 'currencyId' => $this->currencyId, 'vendor' => $this->vendor, '@picture' => $this->images, ]) ->merge($this->additional) ->reject(static fn (mixed $value) => blank($value)) ->all(); }} ``` -------------------------------- ### JSON Output Format for feed:generate Source: https://feeds.dragon-code.pro/generation The command emits a single JSON object containing the status of each feed class, including file paths and record counts for successful generations. ```json { "tool": "feed:generate", "result": "success", "feeds": [ { "class": "App\\Feeds\\SitemapFeed", "status": "generated", "files": [ { "path": "/var/www/html/storage/app/public/sitemap.xml", "records": 1250 } ] }, { "class": "App\\Feeds\\DisabledFeed", "status": "skipped" } ] } ``` -------------------------------- ### XML output for feed information Source: https://feeds.dragon-code.pro/elements The resulting XML structure including the information block. ```xml Laravelhttps://example.com 1 User 1 2 User 2 ``` -------------------------------- ### Implement Custom Attributes Source: https://feeds.dragon-code.pro/elements Define custom XML attributes for feed items by extending the FeedItem class and implementing the attributes method. ```php namespace App\Feeds;use App\Feeds\Items\AttributeFeedItem;use App\Models\User;use DragonCode\LaravelFeed\Feeds\Feed;use DragonCode\LaravelFeed\Feeds\Items\FeedItem;use Illuminate\Database\Eloquent\Builder;use Illuminate\Database\Eloquent\Model;class AttributeFeed extends Feed{ public function builder(): Builder { return User::query(); } public function item(Model $model): FeedItem { return new AttributeFeedItem($model); }} ``` ```php namespace App\Feeds\Items;use DragonCode\LaravelFeed\Feeds\Items\FeedItem;class AttributeFeedItem extends FeedItem{ public function attributes(): array { return [ 'created_at' => $this->model->created_at, ]; }} ``` ```xml 1 User 1 2 User 2 ``` -------------------------------- ### Generate a specific feed Source: https://feeds.dragon-code.pro/generation Executes a single feed by providing its ID, regardless of its active status. ```bash php artisan feed:generate 123 ``` -------------------------------- ### Generate a feed using GeneratorService Source: https://feeds.dragon-code.pro/api/runtime Resolves the service via the Laravel container to generate and process feed results. ```php use App eeds\UserFeed;use DragonCode\LaravelFeed\Services\GeneratorService;$result = app(GeneratorService::class)->feed(app(UserFeed::class));foreach ($result->records as $path => $count) { processFeedResult($path, $count);} ```