Skip to main content

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

Read more here

LaraBug/larabug-app

218 stars
1 code files
View LaraBug/larabug-app on GitHub

app/Console/Commands/RotateExceptions.php

Open in GitHub
use App\Models\User;
use Illuminate\Console\Command;
 
class RotateExceptions extends Command
{
protected $signature = 'rotate:exceptions';
 
protected $description = 'Rotates all the exceptions that are expired';
 
protected $starterRetention = 30;
 
public function handle()
{
$users = User::query()
->whereHas('projects', function ($query) {
return $query->whereHas('exceptions', function ($query) {
return $query->where('created_at', '<', now()->subDays($this->starterRetention));
});
})
->with(['projects' => function ($query) {
return $query
->whereHas('exceptions', function ($query) {
return $query->where('created_at', '<', now()->subDays($this->starterRetention));
});
}])
->get();
 
foreach ($users as $user) {
foreach ($user->projects as $project) {
$project->exceptions()->where('created_at', '<', now()->subDays($this->starterRetention))->delete();
}
}
}
}

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.