Skip to main content

Feeds and data

The core API separates the data source, item mapping, feed-level metadata, output structure, and generation result.

Feed

DragonCode\LaravelFeed\Feeds\Feed is the base class for an export. Implement builder() and override only the output hooks your feed needs.

abstract public function builder(): Builder
MethodDefaultContract
builder(): BuilderAbstractReturns the Eloquent query used as the data source.
item(Model $model): FeedItemNew base FeedItemMaps one model to an output item.
transformers(): array[]Prepends transformer class names for this feed.
chunkSize(): int1000Database query chunk size.
perFile(): int0Records per file. Zero disables splitting by count.
maxFiles(): int0Maximum number of output files. Zero means no limit.
header(): stringXML declaration for XML/RSSContent written before the root and items.
footer(): stringEmpty stringContent written after the root and items.
root(): ElementDataClass-derived element nameDefines the root element and attributes.
info(): FeedInfoEmpty FeedInfoDefines feed-level information.
filename(): stringClass-derived filenameReturns the disk-relative output filename.
path($suffix): stringAdapter-resolved pathReturns a local or adapter-resolved path.
storagePath($suffix): stringDisk-relative filenameReturns the path used for storage operations.
storage(): FilesystemAdapterpublic diskResolves and validates the Laravel filesystem disk.
format(): FeedFormatEnumXmlReturns the configured output format.

Feed uses Laravel Conditionable and Macroable.

Feed targets

DragonCode\LaravelFeed\Feeds\FeedTarget identifies one independently generated output. Its constructor accepts a non-empty string key and an optional parameter array:

public function __construct(public readonly string $key, public readonly array $parameters = [])

Implement DragonCode\LaravelFeed\Contracts\HasFeedTargets on an opt-in feed class. The optional DragonCode\LaravelFeed\Concerns\InteractsWithFeedTargets trait implements forTarget() and target(); the feed class implements discovery:

MethodContract
targets(): iterableLazily returns every available FeedTarget for full command and scheduled runs.
findTarget(string $key): ?FeedTargetDirectly resolves one explicit command target with the same key or returns null.
forTarget(FeedTarget $target): staticReturns a configured clone and resets its memoized filename.
target(): FeedTargetReturns the configured target or throws LogicException when none is set.

The constructor rejects empty and whitespace-only keys but does not normalize or sanitize other values. Target parameters are opaque to the package and serialized as a queue-job snapshot. The key is the target identity, so it must be stable and unique within the feed class. See separate output file setup and command selection.

FeedItem and FeedInfo

FeedItem receives the current Eloquent model. Its defaults are:

  • name() returns the model class basename in kebab case;
  • attributes() returns an empty array;
  • toArray() returns the model array.

FeedInfo::toArray() returns an empty array. Both classes use Conditionable and Macroable; extend them when the output needs an explicit schema.

ElementData

ElementData is a readonly object with three constructor properties:

PropertyTypeDefault
name?stringnull
attributesarray[]
beforeInfobooltrue

Set name to null or an empty string to suppress the root element. Set beforeInfo to false to write feed information before the root.

Generation result

GeneratorService::feed() returns GenerationResultData. Its readonly paths property contains published files in output order. Its readonly records property maps each path to the number of records written to that file.

Programmatic generation and registration methods are listed in runtime services and contracts.

FeedFormatEnum

CaseValue
Xmlxml
Jsonjson
JsonLinesjsonl
Csvcsv
Rssrss

See Also