diff --git a/app/Console/Commands/DeleteOldMessages.php b/app/Console/Commands/DeleteOldMessages.php new file mode 100644 index 0000000..9bd717d --- /dev/null +++ b/app/Console/Commands/DeleteOldMessages.php @@ -0,0 +1,47 @@ +get()->map(function ($message) { + $chatFrom = Chat::query()->where(['id' => $message->chat_id_from])->first(); + if (!$chatFrom) { + $chatFrom->delete(); + } + $chatTo = Chat::query()->where(['id' => $message->chat_id_to])->first(); + if (!$chatTo) { + $chatTo->delete(); + } + }); + + + return Command::SUCCESS; + } +}