Skip to main content

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

Read more here

caneara/tipsea

13 stars
2 code files
View caneara/tipsea on GitHub

app/Jobs/ProcessTipsJob.php

Open in GitHub
use App\Types\Job;
use App\Models\Tip;
use Illuminate\Database\Eloquent\Collection;
 
class ProcessTipsJob extends Job
{
protected array $fields = [
'tips.id',
'tips.user_id',
'tips.slug',
'tips.summary',
'tips.first_tag',
];
 
public int $tries = 1;
 
public function handle() : void
{
Tip::query()
->select($this->fields)
->join('users', 'tips.user_id', '=', 'users.id')
->where('shared', false)
->whereBetween('published_at', [now()->subDay(), now()])
->chunkById(50, fn($tips) => $this->process($tips));
}
 
public function process(Collection $tips) : void
{
$query = Tip::whereIn('id', $tips->pluck('id'));
 
attempt(fn() => $query->update(['shared' => true]));
 
$tips->each(fn($tip) => PostToSocialMediaJob::dispatch($tip));
}
}

app/Commands/ProcessTipsCommand.php

Open in GitHub
use App\Jobs\ProcessTipsJob;
use Illuminate\Console\Command;
 
class ProcessTipsCommand extends Command
{
protected $signature = 'system:process-tips';
 
protected $description = 'Publish scheduled tips and notify followers.';
 
public function handle() : void
{
ProcessTipsJob::dispatch();
 
$this->info('The tips are being processed');
}
}

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.