How to delete notification in command?

I tried this but not working
public function handle()
{
$files = Storage::files('error-reports');

foreach ($files as $file) {
$lastModified = Carbon::createFromTimestamp(Storage::lastModified($file));

$this->line("Checking: {$file} | Modified: {$lastModified}");

if (now()->greaterThan($lastModified->addHours(24))) {
Storage::delete($file);
$this->info(":white_check_mark: Deleted: {$file}");

// Delete related notifications
DatabaseNotification::query()
->where('data->filename', $file)
->delete();

$this->info(":broom: Removed notifications related to {$file}");
} else {
$this->line(":hourglass_flowing_sand: Skipped (not old enough)");
}

}

$this->info('Old error reports cleaned up.');
}
public function handle()
{
$files = Storage::files('error-reports');

foreach ($files as $file) {
$lastModified = Carbon::createFromTimestamp(Storage::lastModified($file));

$this->line("Checking: {$file} | Modified: {$lastModified}");

if (now()->greaterThan($lastModified->addHours(24))) {
Storage::delete($file);
$this->info(":white_check_mark: Deleted: {$file}");

// Delete related notifications
DatabaseNotification::query()
->where('data->filename', $file)
->delete();

$this->info(":broom: Removed notifications related to {$file}");
} else {
$this->line(":hourglass_flowing_sand: Skipped (not old enough)");
}

}

$this->info('Old error reports cleaned up.');
}
noification data {"actions":[],"body":"\u2705 Imported Members: 0<br>\ud83d\udd01 Skipped Members: 1 (duplicate or missing)<br>\u274c Not Imported Members: 1 (validation errors)<br><br>\ud83e\uddfe filename:import-members-errors_20250707_084657_ARn4rn.xlsx<br>- Rey Almario | rey.almario@email.com | 2139304561234 | Number requires a country to be specified.<br><br>\n\n\ud83d\udce5 <a href="http://loyalty-program-api.test/storage/error-reports/import-members-errors_20250707_084657_ARn4rn.xlsx" target="_blank" style="color:#3b82f6;text-decoration:underline;">Download full error report</a><br><span style="color:#f59e0b;">\u26a0\ufe0f This link will expire in 24 hours.</span>","color":null,"duration":"persistent","icon":"heroicon-o-check-circle","iconColor":"success","status":"success","title":"Import Summary","view":"filament-notifications::notification","viewData":[],"format":"filament"}
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?