Skip to content

Commit 4abe79c

Browse files
Added defaults and examples for preset-specific feed items
1 parent ba35e6f commit 4abe79c

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

docs/snippets/preset-instagram.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Feeds;
6+
7+
use App\Models\Product;
8+
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
9+
use DragonCode\LaravelFeed\Presets\InstagramFeedPreset;
10+
use Illuminate\Database\Eloquent\Builder;
11+
use Illuminate\Database\Eloquent\Model;
12+
13+
class InstagramFeed extends InstagramFeedPreset
14+
{
15+
public function builder(): Builder
16+
{
17+
return Product::query();
18+
}
19+
20+
public function item(Model $model): FeedItem
21+
{
22+
return parent::item($model)
23+
->title($model->title)
24+
->description($model->description)
25+
->brand($model->brand) // By default, null
26+
->url($model->url)
27+
->price(price: $model->price, salePrice: $model->price) // By default, salePrice = price
28+
->image($model->images[0])
29+
->images($model->images) // By default, null
30+
->availability($model->quantity > 0 ? 'in stock' : 'out of stock') // By default, 'in stock'
31+
->status($model->quantity > 0 ? 'active' : 'inactive') // By default, 'active'
32+
->condition('new') // By default, 'new'
33+
->group(12345) // By default, null
34+
->googleCategory(123) // By default, null
35+
->facebookCategory(456) // By default, null
36+
->additional([
37+
'g:foo' => 'Some foo',
38+
'g:bar' => 'Some bar',
39+
40+
'g:baz' => [
41+
'@attributes' => ['qwe' => 'rty'],
42+
'@value' => 'Some baz',
43+
],
44+
45+
'@g:arrayable' => [
46+
'a',
47+
'b',
48+
'c',
49+
],
50+
]);
51+
}
52+
}

docs/snippets/receipt-instagram-feed.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ public function item(Model $model): FeedItem
4949
],
5050
]);
5151
}
52+
53+
public function filename(): string
54+
{
55+
return 'instagram.xml';
56+
}
5257
}

docs/topics/presets.topic

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,52 @@
3434
Then implement the two required methods — <code>builder</code> and <code>item</code>. For example:
3535
</p>
3636

37-
<code-block lang="php" src="receipt-instagram-feed.php" include-lines="5-" />
37+
<code-block lang="php" src="preset-instagram.php" include-lines="5-" />
3838

3939
<p>
4040
Technically, preset classes are the same as the base
4141
<code>Feed</code> class, except they include the service-specific logic they target, including how information blocks and items are built.
4242
</p>
43+
44+
<chapter title="Defaults" id="defaults">
45+
<chapter title="Instagram" id="instagram">
46+
<code-block
47+
lang="php"
48+
src="../../src/Presets/Items/InstagramFeedItem.php"
49+
include-lines="13-"
50+
collapsible="true"
51+
default-state="collapsed"
52+
/>
53+
</chapter>
54+
55+
<chapter title="Yandex" id="yandex">
56+
<code-block
57+
lang="php"
58+
src="../../src/Presets/Items/YandexFeedItem.php"
59+
include-lines="13-"
60+
collapsible="true"
61+
default-state="collapsed"
62+
/>
63+
</chapter>
64+
65+
<chapter title="Sitemap" id="sitemap">
66+
<code-block
67+
lang="php"
68+
src="../../src/Presets/Items/SitemapFeedItem.php"
69+
include-lines="11-"
70+
collapsible="true"
71+
default-state="collapsed"
72+
/>
73+
</chapter>
74+
75+
<chapter title="RSS Atom" id="rss">
76+
<code-block
77+
lang="php"
78+
src="../../src/Presets/Items/RssFeedItem.php"
79+
include-lines="14-"
80+
collapsible="true"
81+
default-state="collapsed"
82+
/>
83+
</chapter>
84+
</chapter>
4385
</topic>

0 commit comments

Comments
 (0)