Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

nabilhassen/larasense

62 stars
2 code files
View nabilhassen/larasense on GitHub

app/Jobs/SyncSourceFeed.php

Open in GitHub
use App\Models\Source;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Carbon;
use willvincent\Feeds\Facades\FeedsFacade;
 
class SyncSourceFeed implements ShouldQueue
{
use Queueable;
 
public function __construct(public Source $source) {}
 
public function handle(): void
{
$feed = FeedsFacade::make([$this->source->url], 20, true);
 
if (filled($feed->error())) {
$feed = FeedsFacade::make([$this->source->url], 20);
}
 
$latestMaterial = $this->source->latestMaterial;
 
foreach ($feed->get_items() as $item) {
$itemPublishedAt = Carbon::parse($item->get_date())->timezone(config('app.timezone'));
 
if (filled($latestMaterial) && $latestMaterial->published_at->greaterThanOrEqualTo($itemPublishedAt)) {
break;
}
 
ProcessFeedItem::dispatch($this->source, $item);
}
 
$this->source->updateLastCheckedAt();
}
}

app/Jobs/ProcessFeedItem.php

Open in GitHub
use App\Actions\CreateMaterial;
use App\Data\MaterialData;
use App\Models\Source;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use SimplePie\Item;
 
class ProcessFeedItem implements ShouldQueue
{
use Queueable;
 
public function __construct(
public Source $source,
public Item $item
) {}
 
public function handle(CreateMaterial $createMaterial): void
{
$createMaterial->handle(
$this->source,
MaterialData::create($this->source->type, $this->item),
);
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.