Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions docs/snippets/preset-instagram.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace App\Feeds;

use App\Models\Product;
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
use DragonCode\LaravelFeed\Presets\InstagramFeedPreset;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class InstagramFeed extends InstagramFeedPreset
{
public function builder(): Builder
{
return Product::query();
}

public function item(Model $model): FeedItem
{
return parent::item($model)
->title($model->title)
->description($model->description)
->brand($model->brand) // By default, null
->url($model->url)
->price(price: $model->price, salePrice: $model->price) // By default, salePrice = price
->image($model->images[0])
->images($model->images) // By default, null
->availability($model->quantity > 0 ? 'in stock' : 'out of stock') // By default, 'in stock'
->status($model->quantity > 0 ? 'active' : 'inactive') // By default, 'active'
->condition('new') // By default, 'new'
->group(12345) // By default, null
->googleCategory(123) // By default, null
->facebookCategory(456) // By default, null
->additional([
'g:foo' => 'Some foo',
'g:bar' => 'Some bar',

'g:baz' => [
'@attributes' => ['qwe' => 'rty'],
'@value' => 'Some baz',
],

'@g:arrayable' => [
'a',
'b',
'c',
],
]);
}
}
5 changes: 5 additions & 0 deletions docs/snippets/receipt-instagram-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ public function item(Model $model): FeedItem
],
]);
}

public function filename(): string
{
return 'instagram.xml';
}
}
44 changes: 43 additions & 1 deletion docs/topics/presets.topic
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,52 @@
Then implement the two required methods — <code>builder</code> and <code>item</code>. For example:
</p>

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

<p>
Technically, preset classes are the same as the base
<code>Feed</code> class, except they include the service-specific logic they target, including how information blocks and items are built.
</p>

<chapter title="Defaults" id="defaults">
<chapter title="Instagram" id="instagram">
<code-block
lang="php"
src="../../src/Presets/Items/InstagramFeedItem.php"
include-lines="13-"
collapsible="true"
default-state="collapsed"
/>
</chapter>

<chapter title="Yandex" id="yandex">
<code-block
lang="php"
src="../../src/Presets/Items/YandexFeedItem.php"
include-lines="13-"
collapsible="true"
default-state="collapsed"
/>
</chapter>

<chapter title="Sitemap" id="sitemap">
<code-block
lang="php"
src="../../src/Presets/Items/SitemapFeedItem.php"
include-lines="11-"
collapsible="true"
default-state="collapsed"
/>
</chapter>

<chapter title="RSS" id="rss">
<code-block
lang="php"
src="../../src/Presets/Items/RssFeedItem.php"
include-lines="14-"
collapsible="true"
default-state="collapsed"
/>
</chapter>
</chapter>
</topic>