Server : LiteSpeed System : Linux server335.web-hosting.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64 User : cardxfeb ( 2452) PHP Version : 8.1.34 Disable Function : NONE Directory : /home/cardxfeb/www/app/Console/Commands/ |
<?php
namespace App\Console\Commands;
use Exception;
use App\Models\User;
use Illuminate\Support\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Mail\PlanExpirationReminder;
use Illuminate\Support\Facades\Mail;
class PlanExpirationMailCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'mail:plan-expiration';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send Mail Before Plan Expiration';
/**
* Execute the console command.
*/
public function handle()
{
try {
$users = User::role('admin')->with(['subscriptions'])->get();
foreach ($users as $user) {
$expirationDate = Carbon::parse($user->subscription->ends_at);
$data = [
'first_name' => $user->first_name,
'last_name' => $user->last_name
];
if ($expirationDate->diffInDays(now()) == getSuperAdminSettingValue('plan_expire_notification')) {
Mail::to($user->email)->send(new PlanExpirationReminder($data));
}
}
Log::info('Plan expiration reminder sent successfully');
} catch (Exception $e) {
Log::info($e->getMessage());
}
}
}