Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
375f152
Added feed management via database
andrey-helldar Sep 2, 2025
dd2867c
Set default attributes in Feed model, clean up FeedSeeder, and update…
andrey-helldar Sep 2, 2025
f70731d
Set default value for `expression` attribute in Feed model
andrey-helldar Sep 2, 2025
b5891b5
Enable database seeding by default in TestCase
andrey-helldar Sep 2, 2025
097840f
Remove unused `expression` attribute from FeedSeeder
andrey-helldar Sep 2, 2025
76a4e7c
Update scripts in composer.json
andrey-helldar Sep 2, 2025
72205a4
Add TODO comment for parameter explanations in feeds config
andrey-helldar Sep 2, 2025
d3806f2
Add `dragon-code/laravel-deploy-operations` to dev dependencies in co…
andrey-helldar Sep 2, 2025
4aef5ad
Remove `format` attribute from Feed model and database structure, set…
andrey-helldar Sep 2, 2025
ca33734
Set default cache driver
andrey-helldar Sep 2, 2025
34d0bcd
Update test setup and composer scripts, remove unused code, and refin…
andrey-helldar Sep 2, 2025
d57c526
Refactor exceptions, enhance FeedQuery logic, and improve test coverage.
andrey-helldar Sep 2, 2025
33d3b26
Add detailed comments to feeds config for clarity and maintainability
andrey-helldar Sep 2, 2025
892fa6f
Add PHPDoc comment for `append` method in Filesystem service
andrey-helldar Sep 2, 2025
1c582f7
Refactoring Filesystem.php
andrey-helldar Sep 2, 2025
f693e06
Refactoring Generator.php
andrey-helldar Sep 2, 2025
affa34a
The tests were switched to parallel mode
andrey-helldar Sep 2, 2025
6804924
Added generation of operations and migration
andrey-helldar Sep 3, 2025
a1b5a45
Replace `toBeReadableFile` with `toBeFile` method
andrey-helldar Sep 3, 2025
fa3ec52
Replace `Composer` class with new helper
andrey-helldar Sep 3, 2025
7a8dcf7
Fix tests
andrey-helldar Sep 3, 2025
97340bf
Fix tests
andrey-helldar Sep 3, 2025
5894258
Fix tests
andrey-helldar Sep 3, 2025
c215292
Changed icons
andrey-helldar Sep 3, 2025
7a46ff9
Update description
andrey-helldar Sep 3, 2025
81f43ea
Upgrade docs
andrey-helldar Sep 3, 2025
eb6bcf9
Remove unused snippets
andrey-helldar Sep 3, 2025
b71b953
Remove unused snippets
andrey-helldar Sep 3, 2025
e9ef188
Update README.md
andrey-helldar Sep 3, 2025
10a9985
Fix typo and add details on feed command behavior in docs
andrey-helldar Sep 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,71 @@ consumers.
> - Chunked queries to database
> - Draft mode for a process
> - Easy property mapping
> - Generation of any XML (feeds, sitemaps, etc.)
> - Generation of any feeds, sitemaps, etc.

## Installation

To get the latest version of **Laravel Feeds**, simply require the project
using [Composer](https://getcomposer.org):
You can install the **Laravel Feeds** package via [Composer](https://getcomposer.org):

```Bash
composer require dragon-code/laravel-feeds
```

After that, publish the configuration file by call the console command:
You should publish
the [migration](database/migrations/2025_09_01_231655_create_feeds_table.php)
and the [config/feeds.php](config/feeds.php) file with:

```bash
php artisan vendor:publish --tag=feeds
php artisan vendor:publish --tag="feeds"
```

> [!WARNING]
>
> Before running migrations, check the database connection settings in the [config/feeds.php](config/feeds.php) file.

Now you can run migrations and proceed to [create feeds](https://feeds.dragon-code.pro/create-feeds.html).

## Basic Usage

### Create Feeds

To create a feed class, use the `make:feed` console command:

```bash
php artisan make:feed User -t
```

As a result of executing the console command, the files `app/Feeds/UserFeed.php` and `app/Feeds/Items/UserFeedItem.php`
will be created.

### Generate Feeds
> [!TIP]
> When creating a feed, an operation/migration will also be created to add it to the database.
>
> If the project uses the [Laravel Deploy Operations](https://deploy-operations.dragon-code.pro), then an operation
> class will be created, otherwise a migration class will be created.
>
> This is necessary to add and manage information about feeds in the database.

Check the [operation/migration](https://feeds.dragon-code.pro/create-feeds.html) file that was created for you and run
the console command:

```bash
# For Laravel Deploy Operations
php artisan operations

# For Laravel Migrations
php artisan migrate
```

To generate feeds, create the classes of feeds and its element, add links to the file `config/feeds.php`, next call the
console command:
To generate all active feeds, use the console command:

```bash
php artisan feed:generate
```

## Documentation

[📚 Check out the full documentation to learn everything that Laravel Feeds has to offer.](https://feeds.dragon-code.pro)
📚 You will find full documentation on the dedicated [documentation](https://feeds.dragon-code.pro) site.

## License

Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
"php": "^8.2",
"ext-dom": "*",
"ext-libxml": "*",
"dragonmantank/cron-expression": "^3.4",
"illuminate/database": "^11.0 || ^12.0",
"illuminate/filesystem": "^11.0 || ^12.0",
"illuminate/support": "^11.0 || ^12.0",
"laravel/prompts": ">=0.3.6"
},
"require-dev": {
"dragon-code/codestyler": "^6.3",
"dragon-code/laravel-deploy-operations": "^7.1",
"mockery/mockery": "^1.6",
"orchestra/testbench": "^9.0 || ^10.0",
"pestphp/pest": "^3.0 || ^4.0",
"pestphp/pest-plugin-laravel": "^3.0 || ^4.0",
Expand All @@ -36,7 +39,8 @@
"psr-4": {
"Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/"
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"config": {
Expand All @@ -63,10 +67,12 @@
"@clear",
"@prepare"
],
"build": "@php vendor/bin/testbench workbench:build --ansi",
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"migrate": "@php vendor/bin/testbench migrate:fresh --seed --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"style": "vendor/bin/pint --parallel --ansi",
"test": "@php vendor/bin/pest --colors=always",
"test": "@php vendor/bin/pest --parallel --colors=always",
"test:update": "@php vendor/bin/pest --colors=always --update-snapshots"
}
}
51 changes: 46 additions & 5 deletions config/feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,52 @@
declare(strict_types=1);

return [
'channels' => [
// App\Feeds\FooFeed::class => (bool) env('FEED_FOO_ENABLED', true),
// App\Feeds\BarFeed::class => (bool) env('FEED_BAR_ENABLED', true),
// App\Feeds\BazFeed::class => (bool) env('FEED_BAZ_ENABLED', false),
/**
* Pretty-print the generated feed output.
*
* When enabled, the resulting XML/JSON will include indentation and
* human‑friendly formatting. Disable for slightly smaller payload size.
*
* By default, false
*/
'pretty' => (bool) env('FEED_PRETTY', false),

/**
* Database table settings used by the package (e.g., for generation logs or state).
*/
'table' => [
/**
* The database connection name to use.
*
* Should match a connection defined in config/database.php under
* the "connections" array.
*/
'connection' => env('DB_CONNECTION', 'sqlite'),

/**
* The database table name used by the package.
*/
'table' => env('FEED_TABLE', 'feeds'),
],

'pretty' => (bool) env('FEED_PRETTY', false),
/**
* Scheduling options for feed generation/update tasks.
*/
'schedule' => [
/**
* Time To Live (in minutes) for the schedule lock or cache.
*
* Controls how frequently a scheduled job may be executed to avoid
* overlapping or excessively frequent runs.
*/
'ttl' => (int) env('FEED_SCHEDULE_TTL', 1440),

/**
* Run scheduled jobs in the background.
*
* When true, tasks will be dispatched to run asynchronously so they do
* not block the current process. Set to false to run in the foreground.
*/
'background' => (bool) env('FEED_SCHEDULE_RUN_BACKGROUND', true),
],
];
48 changes: 48 additions & 0 deletions database/migrations/2025_09_01_231655_create_feeds_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up(): void
{
$this->schema()->create($this->table(), function (Blueprint $table) {
$table->id();

$table->string('class')->unique();
$table->string('title');

$table->string('expression');

$table->boolean('is_active');

$table->timestamp('last_activity')->nullable();
$table->timestamps();
$table->softDeletes();
});
}

public function down(): void
{
$this->schema()->dropIfExists($this->table());
}

protected function schema(): Builder
{
return Schema::connection($this->connection());
}

protected function connection(): ?string
{
return config('feeds.table.connection');
}

protected function table(): string
{
return config('feeds.table.table');
}
};
Binary file modified docs/images/laravel-idea.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/laravel-idea_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/laravel-feeds.tree
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<toc-element topic="advanced-usage.topic" />
</toc-element>
<toc-element toc-title="Receipts">
<toc-element topic="sitemap.topic" />
<toc-element topic="instagram.topic" />
<toc-element topic="yandex.topic" />
<toc-element topic="receipt-sitemap.topic" />
<toc-element topic="receipt-instagram.topic" />
<toc-element topic="receipt-yandex.topic" />
</toc-element>
</instance-profile>
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@

class UserFeed extends Feed
{
protected string $storage = 'public';
public function chunkSize(): int
{
return 500;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

declare(strict_types=1);

namespace App\Feeds;

use DragonCode\LaravelFeed\Feeds\Feed;

class UserFeed extends Feed
Expand All @@ -12,4 +10,9 @@ public function header(): string
{
return '<?xml version="1.0" encoding="UTF-8"?>';
}

public function footer(): string
{
return '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class UserFeedInfo extends FeedInfo
public function toArray(): array
{
return [
// ...
'name' => config('app.name'),
'company' => config('app.name'),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

declare(strict_types=1);

namespace App\Feeds;

use App\Feeds\Info\UserFeedInfo;
use DragonCode\LaravelFeed\Feeds\Feed;
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;

class UserFeed extends Feed
{
public function info(): FeedInfo
{
return new FeedInfo;
return new UserFeedInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

class UserFeed extends Feed
{
protected string $storage = 'public';

public function filename(): string
{
return 'your/path/may/be/here.xml';
return 'some/path/will/be/here.xml';
}
}
4 changes: 2 additions & 2 deletions docs/snippets/advanced-nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class UserFeedItem extends FeedItem
public function toArray(): array
{
return [
'name' => $this->model->name,
'name' => $this->model->class,
'email' => $this->model->email,

'header' => [
'@cdata' => '<h1>' . $this->model->name . '</h1>',
'@cdata' => '<h1>' . $this->model->class . '</h1>',
],

'names' => [
Expand Down
2 changes: 0 additions & 2 deletions docs/snippets/config-channels.ini

This file was deleted.

5 changes: 0 additions & 5 deletions docs/snippets/config-pretty-false.xml

This file was deleted.

13 changes: 0 additions & 13 deletions docs/snippets/config-pretty-true.xml

This file was deleted.

File renamed without changes.
8 changes: 0 additions & 8 deletions docs/snippets/feeds-feed-item-result.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,8 @@ class UserFeedItem extends FeedItem
public function toArray(): array
{
return [
'name' => $this->model->name,
'name' => $this->model->class,
'email' => $this->model->email,

'header' => [
'@attributes' => [
'my-key-1' => 'my value 1',
'my-key-2' => 'my value 2',
],
'@cdata' => '<h1>' . $this->model->name . '</h1>',
],
];
}
}
9 changes: 0 additions & 9 deletions docs/snippets/receipt-instagram-config.php

This file was deleted.

9 changes: 0 additions & 9 deletions docs/snippets/receipt-sitemap-config.php

This file was deleted.

Loading