Files
exchange-2.0/app/Console/Commands/RemoveSeasonalSegmentCompany.php
T
2023-03-20 11:08:16 +08:00

58 lines
1.5 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\SeasonalSegment;
use Illuminate\Console\Command;
use Carbon\Carbon;
use App\Classes\Modules\Companies\Services\RemovesCompanyFromSegment;
class RemoveSeasonalSegmentCompany extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'seasonalSegmantCompany:remove';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Perform soft delete on Seasonal Segment Company';
/** @var RemovesCompanyFromSegment */
private $removesCompanyFromSegment;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(RemovesCompanyFromSegment $removesCompanyFromSegment)
{
parent::__construct();
$this->removesCompanyFromSegment = $removesCompanyFromSegment;
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$seasonalSegment = SeasonalSegment::where('ending_on', '<=', Carbon::today())->get();
if (count($seasonalSegment)){
foreach ($seasonalSegment as $seasonalSegmentCompany) {
$this->removesCompanyFromSegment->execute($seasonalSegmentCompany->company, $seasonalSegmentCompany->segment);
$seasonalSegmentCompany->delete();
$this->info(Carbon::now() . ' : Deleted id: ' . $seasonalSegmentCompany->id);
}
}
}
}