Skip to content

Commit c86e3e8

Browse files
Merge pull request #58 from TheDragonCode/1.x
Added feed management via database
2 parents 4471a62 + 10a9985 commit c86e3e8

File tree

112 files changed

+1661
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1661
-662
lines changed

README.md

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,71 @@ consumers.
1616
> - Chunked queries to database
1717
> - Draft mode for a process
1818
> - Easy property mapping
19-
> - Generation of any XML (feeds, sitemaps, etc.)
19+
> - Generation of any feeds, sitemaps, etc.
2020
2121
## Installation
2222

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

2625
```Bash
2726
composer require dragon-code/laravel-feeds
2827
```
2928

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

3233
```bash
33-
php artisan vendor:publish --tag=feeds
34+
php artisan vendor:publish --tag="feeds"
3435
```
3536

37+
> [!WARNING]
38+
>
39+
> Before running migrations, check the database connection settings in the [config/feeds.php](config/feeds.php) file.
40+
41+
Now you can run migrations and proceed to [create feeds](https://feeds.dragon-code.pro/create-feeds.html).
42+
3643
## Basic Usage
3744

3845
### Create Feeds
3946

47+
To create a feed class, use the `make:feed` console command:
48+
4049
```bash
4150
php artisan make:feed User -t
4251
```
4352

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

47-
### Generate Feeds
56+
> [!TIP]
57+
> When creating a feed, an operation/migration will also be created to add it to the database.
58+
>
59+
> If the project uses the [Laravel Deploy Operations](https://deploy-operations.dragon-code.pro), then an operation
60+
> class will be created, otherwise a migration class will be created.
61+
>
62+
> This is necessary to add and manage information about feeds in the database.
63+
64+
Check the [operation/migration](https://feeds.dragon-code.pro/create-feeds.html) file that was created for you and run
65+
the console command:
66+
67+
```bash
68+
# For Laravel Deploy Operations
69+
php artisan operations
70+
71+
# For Laravel Migrations
72+
php artisan migrate
73+
```
4874

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

5277
```bash
5378
php artisan feed:generate
5479
```
5580

5681
## Documentation
5782

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

6085
## License
6186

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
"php": "^8.2",
1515
"ext-dom": "*",
1616
"ext-libxml": "*",
17+
"dragonmantank/cron-expression": "^3.4",
1718
"illuminate/database": "^11.0 || ^12.0",
1819
"illuminate/filesystem": "^11.0 || ^12.0",
1920
"illuminate/support": "^11.0 || ^12.0",
2021
"laravel/prompts": ">=0.3.6"
2122
},
2223
"require-dev": {
2324
"dragon-code/codestyler": "^6.3",
25+
"dragon-code/laravel-deploy-operations": "^7.1",
26+
"mockery/mockery": "^1.6",
2427
"orchestra/testbench": "^9.0 || ^10.0",
2528
"pestphp/pest": "^3.0 || ^4.0",
2629
"pestphp/pest-plugin-laravel": "^3.0 || ^4.0",
@@ -36,7 +39,8 @@
3639
"psr-4": {
3740
"Tests\\": "tests/",
3841
"Workbench\\App\\": "workbench/app/",
39-
"Workbench\\Database\\Factories\\": "workbench/database/factories/"
42+
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
43+
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
4044
}
4145
},
4246
"config": {
@@ -63,10 +67,12 @@
6367
"@clear",
6468
"@prepare"
6569
],
70+
"build": "@php vendor/bin/testbench workbench:build --ansi",
6671
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
72+
"migrate": "@php vendor/bin/testbench migrate:fresh --seed --ansi",
6773
"prepare": "@php vendor/bin/testbench package:discover --ansi",
6874
"style": "vendor/bin/pint --parallel --ansi",
69-
"test": "@php vendor/bin/pest --colors=always",
75+
"test": "@php vendor/bin/pest --parallel --colors=always",
7076
"test:update": "@php vendor/bin/pest --colors=always --update-snapshots"
7177
}
7278
}

config/feeds.php

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,52 @@
33
declare(strict_types=1);
44

55
return [
6-
'channels' => [
7-
// App\Feeds\FooFeed::class => (bool) env('FEED_FOO_ENABLED', true),
8-
// App\Feeds\BarFeed::class => (bool) env('FEED_BAR_ENABLED', true),
9-
// App\Feeds\BazFeed::class => (bool) env('FEED_BAZ_ENABLED', false),
6+
/**
7+
* Pretty-print the generated feed output.
8+
*
9+
* When enabled, the resulting XML/JSON will include indentation and
10+
* human‑friendly formatting. Disable for slightly smaller payload size.
11+
*
12+
* By default, false
13+
*/
14+
'pretty' => (bool) env('FEED_PRETTY', false),
15+
16+
/**
17+
* Database table settings used by the package (e.g., for generation logs or state).
18+
*/
19+
'table' => [
20+
/**
21+
* The database connection name to use.
22+
*
23+
* Should match a connection defined in config/database.php under
24+
* the "connections" array.
25+
*/
26+
'connection' => env('DB_CONNECTION', 'sqlite'),
27+
28+
/**
29+
* The database table name used by the package.
30+
*/
31+
'table' => env('FEED_TABLE', 'feeds'),
1032
],
1133

12-
'pretty' => (bool) env('FEED_PRETTY', false),
34+
/**
35+
* Scheduling options for feed generation/update tasks.
36+
*/
37+
'schedule' => [
38+
/**
39+
* Time To Live (in minutes) for the schedule lock or cache.
40+
*
41+
* Controls how frequently a scheduled job may be executed to avoid
42+
* overlapping or excessively frequent runs.
43+
*/
44+
'ttl' => (int) env('FEED_SCHEDULE_TTL', 1440),
45+
46+
/**
47+
* Run scheduled jobs in the background.
48+
*
49+
* When true, tasks will be dispatched to run asynchronously so they do
50+
* not block the current process. Set to false to run in the foreground.
51+
*/
52+
'background' => (bool) env('FEED_SCHEDULE_RUN_BACKGROUND', true),
53+
],
1354
];
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Database\Schema\Builder;
8+
use Illuminate\Support\Facades\Schema;
9+
10+
return new class extends Migration {
11+
public function up(): void
12+
{
13+
$this->schema()->create($this->table(), function (Blueprint $table) {
14+
$table->id();
15+
16+
$table->string('class')->unique();
17+
$table->string('title');
18+
19+
$table->string('expression');
20+
21+
$table->boolean('is_active');
22+
23+
$table->timestamp('last_activity')->nullable();
24+
$table->timestamps();
25+
$table->softDeletes();
26+
});
27+
}
28+
29+
public function down(): void
30+
{
31+
$this->schema()->dropIfExists($this->table());
32+
}
33+
34+
protected function schema(): Builder
35+
{
36+
return Schema::connection($this->connection());
37+
}
38+
39+
protected function connection(): ?string
40+
{
41+
return config('feeds.table.connection');
42+
}
43+
44+
protected function table(): string
45+
{
46+
return config('feeds.table.table');
47+
}
48+
};

docs/images/laravel-idea.png

2.21 KB
Loading

docs/images/laravel-idea_dark.png

-1.07 KB
Loading

docs/laravel-feeds.tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<toc-element topic="advanced-usage.topic" />
2020
</toc-element>
2121
<toc-element toc-title="Receipts">
22-
<toc-element topic="sitemap.topic" />
23-
<toc-element topic="instagram.topic" />
24-
<toc-element topic="yandex.topic" />
22+
<toc-element topic="receipt-sitemap.topic" />
23+
<toc-element topic="receipt-instagram.topic" />
24+
<toc-element topic="receipt-yandex.topic" />
2525
</toc-element>
2626
</instance-profile>

docs/snippets/generation-feed-storage.php renamed to docs/snippets/advanced-feed-chunk.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66

77
class UserFeed extends Feed
88
{
9-
protected string $storage = 'public';
9+
public function chunkSize(): int
10+
{
11+
return 500;
12+
}
1013
}

docs/snippets/advanced-header.php renamed to docs/snippets/advanced-feed-header-and-footer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Feeds;
6-
75
use DragonCode\LaravelFeed\Feeds\Feed;
86

97
class UserFeed extends Feed
@@ -12,4 +10,9 @@ public function header(): string
1210
{
1311
return '<?xml version="1.0" encoding="UTF-8"?>';
1412
}
13+
14+
public function footer(): string
15+
{
16+
return '';
17+
}
1518
}

docs/snippets/advanced-head-info.php renamed to docs/snippets/advanced-feed-info-class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class UserFeedInfo extends FeedInfo
1111
public function toArray(): array
1212
{
1313
return [
14-
// ...
14+
'name' => config('app.name'),
15+
'company' => config('app.name'),
1516
];
1617
}
1718
}

0 commit comments

Comments
 (0)