Skip to main content
Version: 1.x

← Previous · Back to README · Next →

Generation & schedule

To generate all active feeds, use the console command:

php artisan feed:generate

As a result, all active feeds (is_active = true) will be executed from the feeds table (or the one you specified in the config/feeds.php file).

tip

Please note that when you call the command without a parameter, the console will display links to all feeds, even those with the is_active property set to false.

However, instead of being executed, such feeds will be marked with the SKIP status.

Single feed​

warning

Please note that the specified feed will be executed even if it is disabled in the feeds table in the database.

To generate a specific feed, call the feed:generate console command, passing the feed slug from the feeds table as its parameter:

php artisan feed:generate products

Generate selected output files​

For a feed configured with separate output files, the registration slug selects the feed class and the target key selects one partner, store, locale, or other output.

Running the feed without --target consumes targets() lazily and generates every target:

php artisan feed:generate products

Pass the repeatable --target option to generate only selected targets:

php artisan feed:generate products --target=42
php artisan feed:generate products --target=42 --target=81

Explicit keys use findTarget() instead of enumerating targets(). Duplicate keys are processed once, in first-seen order. All requested keys are resolved before generation starts.

--target requires one feed registration slug. The command rejects empty or unknown keys and rejects target selection for a feed that does not implement HasFeedTargets.

Full target enumeration is streamed rather than atomic. If targets() fails after yielding some values, earlier targets may already be generated or queued. An empty iterable generates nothing and does not create an implicit default target.

AI agent output​

When feed:generate runs inside an AI coding agent recognized by Laravel Agent Detector, it automatically writes a single JSON object instead of progress bars and formatted status lines. No command option is required. Outside a recognized agent, the regular console output remains unchanged.

For direct generation, each generated feed includes every published file and its record count:

{
"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"
}
]
}

The command emits compact JSON on one line. The example is formatted only for readability.

StatusMeaningAdditional fields
generatedThe feed files were generated directly.files, containing path and records for each file
queuedQueue mode is enabled and the feed job was dispatched synchronously for the agent.None
skippedThe feed is inactive and the command was run without a feed slug.None

Each targeted generated or queued entry also contains a target field with the selected key.

note

In queue mode, the agent-aware path runs each enabled job synchronously before returning the JSON result. The regular human-oriented path continues to dispatch jobs through the configured queue connection.

Only successful runs use this JSON envelope. If generation throws an exception, Laravel handles the command error normally and no JSON error envelope is emitted.

Queue​

Feed generation runs in the console process by default. For feeds that take a long time or use a large amount of memory, enable Laravel Queue mode in your environment:

FEED_QUEUE_ENABLED=true
FEED_QUEUE_CONNECTION=redis
FEED_QUEUE_NAME=feeds
FEED_QUEUE_UNIQUE_TTL=3600

When queue mode is enabled, feed:generate dispatches one job for every ordinary active feed and one job for every selected target of a targeted feed. With an asynchronous connection, the command returns after the jobs have been dispatched. Start a queue worker for the selected connection and queue to process those jobs.

  • FEED_QUEUE_CONNECTION selects the queue connection. It falls back to QUEUE_CONNECTION and then to database.
  • FEED_QUEUE_NAME selects a queue on that connection. Leave it unset to use the connection's default queue.
  • FEED_QUEUE_UNIQUE_TTL sets the maximum lifetime of the uniqueness lock in seconds. Ordinary jobs are unique by feed class. Targeted jobs are unique by feed class and target key; target parameters do not change that identity.
note

The sync connection executes each job immediately in the console process. Select an asynchronous connection to move generation to a worker. Set FEED_QUEUE_ENABLED=false to generate feeds directly without dispatching jobs.

Schedule​

Registration expression​

Pass either a raw cron expression string or a fluent DragonCode\LaravelFeed\Scheduling\Expression when creating a feed registration.

use App\Feeds\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'),
);

The fluent example stores 0 13 * * 1. Raw strings, including aliases supported by dragonmantank/cron-expression such as @daily, remain supported.

Available fluent methods follow the schedule frequency options provided by the installed Laravel version. See the Laravel 13 frequency reference for the current list. Only methods whose result can be stored as a stable five-field cron expression are exposed. Sub-minute intervals, timezones, time-window constraints, and lastDayOfMonth() are not available on this value object.

Automatic​

To automate feed generation, use a schedule. To do this, specify the helper call in the routes/console.php file (the default path, unless you have changed it):

use DragonCode\LaravelFeed\Helpers\ScheduleFeedHelper;
use Illuminate\Support\Facades\Schedule;

ScheduleFeedHelper::register();

Schedule::call(function () {
// ... other action
})->everySecond();

This registers all active feeds according to the schedule in the database expression column. A scheduled targeted feed generates every value returned by targets().

Manual​

You can also specify the schedule directly according to your own rules. In this case, only the feeds you specify will be executed.

use DragonCode\LaravelFeed\Commands\FeedGenerateCommand;
use Illuminate\Support\Facades\Schedule;

Schedule::command(FeedGenerateCommand::class, ['products'])
->withoutOverlapping()
->runInBackground()
->daily();

Schedule::command(FeedGenerateCommand::class, ['sitemap'])
->withoutOverlapping()
->runInBackground()
->hourly();

Schedule::call(function () {
// ... other action
})->everySecond();

See Also​