ldc-loue/app/Jobs/SlidersStatusUpdate.php

42 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Jobs;
use App\Models\Slider;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log;
/**
* Update published and visibility attributes reading their
* publish_at and unpublish_at attributes.
*/
class SlidersStatusUpdate
{
/**
* Called when the job will be executed.
*
* @return void
*/
public function handle()
{
$slidersToPublish = Slider::where('publish_at', '<=', Carbon::now()->toDateTime())
->whereNotNull('publish_at')
->whereStatus(false)->get();
Log::debug(__CLASS__ . " sliders to publish " . $slidersToPublish->count());
foreach ($slidersToPublish as $slider) {
$slider->publish_at = null;
$slider->status = true;
$slider->saveOrFail();
}
$slidersToUnPublish = Slider::where('unpublish_at', '<=', Carbon::now()->toDateTime())
->whereNotNull('unpublish_at')
->whereStatus(true)->get();
Log::debug(__CLASS__ . " sliders to unpublish " . $slidersToPublish->count());
foreach ($slidersToUnPublish as $slider) {
$slider->unpublish_at = null;
$slider->status = false;
$slider->saveOrFail();
}
}
}